从模块内提取资源文件
2010年7月30日
void ExtractBinResource( HMODULE hModule, LPCTSTR lpResKind, int nResID,
LPCTSTR lpOutFile )
{
HGLOBAL hResourceLoaded = NULL; // handle to loaded resource
HRSRC hRes = NULL; // handle/ptr. to res. info.
LPCVOID lpResLock = NULL; // pointer to resource data
DWORD dwSizeRes = 0;
// find location of the resource and get handle to it
hRes = FindResource( hModule, MAKEINTRESOURCE(nResID), lpResKind );
// loads the specified resource into global memory.
hResourceLoaded = LoadResource( hModule, hRes );
// get a pointer to the loaded resource!
lpResLock = (LPCVOID)LockResource( hResourceLoaded );
// determine the size of the resource,
// so we know how much to write out to file!
dwSizeRes = SizeofResource( hModule, hRes );
HANDLE hFile = CreateFile(lpOutFile, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
WriteFile(hFile, lpResLock, dwSizeRes, &dwSizeRes, NULL);
CloseHandle(hFile);
}
}

近期评论