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

你可能感兴趣的:(资源,dll,解压,保存)