嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
向EXE写资源
BOOL writeResource(const std::wstring& sExeFile, const std::wstring& sResourceFile, const std::wstring& sResourceName)
{
if (sExeFile == L"" || sResourceFile == L"")
{
return FALSE;
}
filebuf *pbuf = NULL;
ifstream filestr;
long size = 0;
char * buffer = NULL;
// 要读入整个文件,必须采用二进制打开
filestr.open(sResourceFile, ios::binary);
// 获取filestr对应buffer对象的指针
pbuf = filestr.rdbuf();
// 调用buffer对象方法获取文件大小
size = pbuf->pubseekoff(0, ios::end, ios::in);
if (size < 1)
{
cout << "error info: pubseekoff size < 1"<< endl;
return FALSE;
}
pbuf->pubseekpos(0, ios::in);
// 分配内存空间
buffer = new char[size];
// 获取文件内容
pbuf->sgetn(buffer, size);
filestr.close();
// 输出到标准输出
//cout.write(buffer, size);
BOOL bResult = FALSE;
HANDLE hResource = BeginUpdateResource(sExeFile.c_str(), FALSE);
if (NULL != hResource)
{
if (FALSE != UpdateResource(hResource, RT_RCDATA, sResourceName.c_str(), LANG_NEUTRAL, (LPVOID)buffer, size))
{
if (EndUpdateResource(hResource, FALSE) != FALSE)
{
cout << "update " << wstring2string(sResourceName) << " success!!!" << endl;
bResult = TRUE;
}
}
}
if (!bResult)
{
cout << "update " << wstring2string(sResourceName) << " error!!!" << endl;
}
delete[]buffer;
return bResult;
}