vc資源中的DLL,保存到磁盤

 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;
 }

發佈了47 篇原創文章 · 獲贊 20 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章