1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <iostream> #include <Windows.h> #include <tchar.h> #include "resource.h"
bool ExtractResource(LPCTSTR strDstFile, LPCTSTR strResType, LPCTSTR strResName) { HANDLE hFile = ::CreateFile( strDstFile, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL ); if (hFile == INVALID_HANDLE_VALUE) return false;
HRSRC hRes = ::FindResource(NULL, strResName, strResType); HGLOBAL hMem = ::LoadResource(NULL, hRes); DWORD dwSize = ::SizeofResource(NULL, hRes);
DWORD dwWrite = 0; ::WriteFile(hFile, hMem, dwSize, &dwWrite, NULL); ::CloseHandle(hFile);
return true; }
int main() { ExtractResource( L"C:\\Users\\xiaoyi\\Desktop\\test\\abc.zip", _T("zip"), MAKEINTRESOURCE(IDR_ZIP1) ); return 0; }
|