visual studio 2010 - Load resource as byte array programmaticaly in C++ -


here same question c#: load resource byte array programmaticaly

so i've got resource (just binary file - user data, dosen't matter). need pointer byte array representing resource, how ? resource located in resource files of vs2010 (win32 console project). think need use findresource, loadresource , lockresource function of winapi.

to obtain byte information of resource, first step obtain handle resource using findresource or findresourceex. then, load resource using loadresource. finally, use lockresource address of data , access sizeofresource bytes point. following example illustrates process:

hmodule hmodule = getmodulehandle(null); // handle current module (the executable file) hrsrc hresource = findresource(hmodule, makeintresource(resource_id), resource_type); // substitute resource_id , resource_type. hglobal hmemory = loadresource(hmodule, hresource); dword dwsize = sizeofresource(hmodule, hresource); lpvoid lpaddress = lockresource(hmemory);  char *bytes = new char[dwsize]; memcpy(bytes, lpaddress, dwsize); 

error handling of course omitted brevity, should check return value of each call.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -