Firstly, I would like to wish everyone a happy, safe and prosperous 2010 :-)
Now, I am trying to extract a bitmap from executable using the following code:
if ( HRSRC hRes = FindResource ( NULL, MAKEINTRESOURCE(IDB_BITMAP
1), RT_BITMAP ) )
if ( HGLOBAL hResLoad = LoadResource ( NULL, hRes ) )
LPVOID pVoid = LockResource ( hResLoad );
DWORD dwSize = SizeofResource ( NULL, hRes );
CFile file ( _T("C:\\test.bmp"), CFile::modeCreate | CFile::modeWrite );
file.Write ( pVoid, dwSize );
The file is created, but when I double click it to open it, I get told it is an invalid bitmap. This code is based on that found at http://www.codeproject.com/KB/winsdk/binaryresources.aspx
, which, incidentally, does not work for bitmap resources either, but does work for custom resources (the article demonstrates extracting an EXE).
So, two questions:
1) Why does this code not work for a bitmap resource?
2) Assuming I can exract the bitmap correctly, I would like to be able to change it (say, using Paint), then re-embed it in my executable, in a similar way we can edit the resources of an executable/DLL in visual studio. How can I do this?
(I assume that 2) is going to be the hardest question :))