Extracting a file from an exe file resource

  • Thread starter Thread starter Tall_Guy_63
  • Start date Start date
T

Tall_Guy_63

Guest
I'm trying to load a file from a resource included in the program's exe file

The file keeps coming out empty, so I guess I'm not writing the string correctly from the pointer to the file.

The openbinaryfile and put$() functions work correctly throughout the program, and always correctly write the std::string to the file, so those are not the issue...

Any ideas what I'm doing wrong ?

//load file data from resource

HRSRC hresource=FindResource(hinstance,L"IDR_FILE",RT_RCDATA);
HGLOBAL hmemory=LoadResource(hinstance,hresource);
DWORD res_size=SizeofResource(hinstance,hresource);
LPVOID p=LockResource(hmemory);

//write resource data at pointer "p" to file "File.dat"

std::string dta=std::string(reinterpret_cast<char*>(p),res_size);

HANDLE ff1=openbinaryfile("File.dat");
put$(ff1,dta);
CloseHandle(ff1);

UnlockResource(hmemory);
FreeResource(hmemory);

//-----------------------------------------------------

Continue reading...
 
Back
Top