C ++将资源写入磁盘

时间:2018-03-07 01:16:46

标签: c++ writefile

我不知道我做错了什么..代码正在创建一个空文件。

RESOURCE.H

#define IDR_RCDATA1 101

RESOURCE.RC

IDR_RCDATA1 RCDATA "A.exe"

的main.cpp

#include "resource.h"
#include <windows.h>

using namespace std;

int main() {

HINSTANCE hInstance = GetModuleHandle(NULL);

HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_RCDATA1), RT_RCDATA);
HGLOBAL hRes = LoadResource(hInstance, hResInfo);
LPVOID memRes = LockResource(hResInfo);
DWORD sizeRes = SizeofResource(hInstance, hResInfo);

HANDLE hFile = CreateFile("B.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwWritten = 0;
WriteFile(hFile, memRes, sizeRes, &dwWritten, NULL);
CloseHandle(hFile);

}

0 个答案:

没有答案