code_ninja Posted June 22, 2009 Share Posted June 22, 2009 I have a dll with a bitmap resource. I want to know how to export that resource, I.E. save it to desktop. Does anyone know how to do it? Link to comment Share on other sites More sharing options...
0 code.kliu.org Posted June 22, 2009 Share Posted June 22, 2009 Programmatically? LoadLibrary to load the DLL, FindResource to get the resource handle, LoadResource to turn that into a memory handle, LockResource to turn that into a memory pointer, and then from that pointer, write SizeofResource bytes to a file of your choosing. Or you can use any old resource editor to extract it manually. Link to comment Share on other sites More sharing options...
0 code_ninja Posted June 22, 2009 Author Share Posted June 22, 2009 kthx Link to comment Share on other sites More sharing options...
0 code_ninja Posted July 15, 2009 Author Share Posted July 15, 2009 OK tried some stuff and it didn't work. Could you give me some example code? Link to comment Share on other sites More sharing options...
0 adsadsads Posted July 15, 2009 Share Posted July 15, 2009 Coded this quick in Textmate, untested: DWORD SaveResource(__in_z LPCTSTR lpcszFileName, __in_z LPCTSTR lpcszType, __in_z LPCTSTR lpcszName, __out_ecount(nSize) PBYTE pbData, __in SIZE_T nSize) { HMODULE hModule; HGLOBAL hGlobal; LPVOID lpBuffer; HRSRC hResource; DWORD dwSize, dwRET = 0; hModule = LoadLibrary(lpcszFileName); if (hModule != NULL) { hResource = FindResource(hModule, lpcszName, lpcszType); if (hResource != NULL) { dwSize = SizeofResource(hModule, hResource); hGlobal = LoadResource(hModule, hResource); if (hGlobal != NULL || dwSize != 0) { lpBuffer = LockResource(hGlobal); __try { CopyMemory(pbData, lpBuffer, min(dwSize, nSize)); dwRET = dwSize; } __catch (EXCEPTION_EXECUTE_HANDLER) { #ifdef _DEBUG OutputDebugString(TEXT("Exception occurred whilst trying to copy resource!\r\n")); #endif } } } FreeLibrary(hModule); // dec load count } return dwRET; } Example Usage: DWORD dwSize; BYTE bResource[1024]; dwSize = SaveResource(TEXT("lol.dll"), TEXT("AUDIO"), TEXT("gaysound.mp3"), bResource, sizeof(bResource)); if (dwSize != 0) _tprintf(TEXT("resource saved! resource size: 0x%08X"), dwSize); else _ftprintf(stderr, TEXT("could not save resource!")); Link to comment Share on other sites More sharing options...
0 code_ninja Posted July 15, 2009 Author Share Posted July 15, 2009 thnx x0r i'll try it out. Link to comment Share on other sites More sharing options...
0 CentralDogma Posted July 16, 2009 Share Posted July 16, 2009 If you're still having trouble, I had a thread about creating and using a DLL in C/C++. I've since refined the code a bit(some of the code is unnecessary) I could try finding it if you still need help. Link to comment Share on other sites More sharing options...
Question
code_ninja
I have a dll with a bitmap resource.
I want to know how to export that resource, I.E. save it to desktop.
Does anyone know how to do it?
Link to comment
Share on other sites
6 answers to this question
Recommended Posts