Skip to content

Instantly share code, notes, and snippets.

@lookat23
Created June 29, 2014 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lookat23/48404a1706861b062994 to your computer and use it in GitHub Desktop.
Save lookat23/48404a1706861b062994 to your computer and use it in GitHub Desktop.
加载资源,然后写成文件
HINSTANCE instance = AfxGetInstanceHandle();
// 定位资源
HRSRC hRsrc = FindResource(instance, MAKEINTRESOURCE(IDR_FILE1), _T("File"));
// 获取资源大小
DWORD dwSize = SizeofResource(instance, hRsrc);
assert(dwSize != 0);
// 加载资源
HGLOBAL hGlobal = LoadResource(instance, hRsrc);
assert(hGlobal != NULL);
// 锁定资源
LPVOID pBuffer = LockResource(hGlobal);
assert(pBuffer != NULL);
FILE* f = fopen("d:\\aa.exe","wb");
assert(f != NULL);
fwrite(pBuffer, dwSize, 1, f);
fclose(f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment