bool ReleaseDll(int dllID, LPCTSTR lpDllPathFileName) //lpDllPathFileName爲完整路徑
{
DWORD dwWritten = 0;
HMODULE hInstance = ::GetModuleHandle(NULL);
// Find the binary file in resources
HRSRC hServiceExecutableRes = ::FindResource(hInstance, MAKEINTRESOURCE(dllID), L"DLL" );
HGLOBAL hServiceExecutable = ::LoadResource(hInstance, hServiceExecutableRes);
LPVOID pServiceExecutable = ::LockResource(hServiceExecutable);
if (pServiceExecutable)
{
DWORD dwServiceExecutableSize = ::SizeofResource( hInstance, hServiceExecutableRes);
HANDLE hFileServiceExecutable = ::CreateFile( lpDllPathFileName,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFileServiceExecutable == INVALID_HANDLE_VALUE)
{
::CloseHandle(hFileServiceExecutable);
return FALSE;
}
::WriteFile(hFileServiceExecutable, pServiceExecutable, dwServiceExecutableSize, &dwWritten, NULL);
::CloseHandle(hFileServiceExecutable);
return TRUE;
}
return FALSE;
}
vc資源中的DLL,保存到磁盤
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.