我使用此代码加载嵌入式资源(位图图像)
HRSRC hResInfo = ::FindResource(hInstance, MAKEINTRESOURCE(resourceId), RT_BITMAP);
HGLOBAL hRes = ::LoadResource(hInstance, hResInfo);
LPVOID memRes = ::LockResource(hRes);
DWORD sizeRes = ::SizeofResource(hInstance, hResInfo);
它工作正常。
如何将其保存到文件C:\image.bmp?
此代码仅创建空文件:
HANDLE hFile = ::CreateFile(L"C:\\image.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwWritten = 0;
::WriteFile(hFile, memRes, sizeRes, &dwWritten, NULL);
::CloseHandle(hFile);
解决方案:
在资源中创建新类型“BMP”并放置图像
HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(resourceId), _T("BMP") );