码迷,mamicode.com
首页 > 其他好文 > 详细

自定义RC资源导出 FindResource LoadResource

时间:2016-07-29 21:01:15      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

1. 查找资源并获取资源内容

/**
* exportPath:文件路径,
*resourceId:资源ID
*/
bool ExportRes(const std::wstring& exportPath, DWORD resourceId)
{
// "DLL" 是自定义资源类型,可以自己决定
HRSRC hrSrc = FindResource(m_hInstance, MAKEINTRESOURCE(resourceId), _T("DLL"));
if (hrSrc == NULL)
{
return false;
}

HGLOBAL hGlobalResource = LoadResource(m_hInstance, hrSrc);
if (hGlobalResource == NULL)
{
return false;
}

const void* pResourceData = ::LockResource(hGlobalResource);
if (!pResourceData)
{
return false;
}

DWORD resLength = SizeofResource(m_hInstance, hrSrc);
bool ret = ExportToFile(exportPath, pResourceData, resLength);

FreeResource(hGlobalResource);
return ret;
}


bool ExportToFile(const std::wstring& exportFilePath, const void* pBuffer, DWORD bufferLength)
{
if (pBuffer == NULL || bufferLength <= 0)
{
return false;
}

HANDLE hFile = ::CreateFile(exportFilePath.c_str(),
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (hFile == NULL)
{
return false;
}

DWORD writetem = -1;
BOOL ret = ::WriteFile(hFile, pBuffer, bufferLength, &writetem, NULL);
if (writetem != bufferLength)
{
::CloseHandle(hFile);
return false;
}

::CloseHandle(hFile);
return true;
}

自定义RC资源导出 FindResource LoadResource

标签:

原文地址:http://www.cnblogs.com/luanwu/p/5719435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!