装入资源

飘雪831101 2009-01-07 03:53:49
如何把图标等通过BeginUpdateResource,UpdateResource等加入啊.
...全文
98 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
飘雪831101 2009-01-09
  • 打赏
  • 举报
回复
选择一个.ico图标,然后updateresource,放入可执行文件中.
怎么实现啊?
Show_Mike 2009-01-08
  • 打赏
  • 举报
回复
如果还有疑问,可查msdn,其中有比较详细的操作过程介绍.
Show_Mike 2009-01-08
  • 打赏
  • 举报
回复
给你一个实例:

HRSRC hResLoad; // handle to loaded resource
HANDLE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
ErrorHandler("Could not load exe.");
}

// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
ErrorHandler("Could not locate dialog box.");
}

// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
ErrorHandler("Could not load dialog box.");
}

// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
ErrorHandler("Could not lock dialog box.");
}

// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("foot.exe", FALSE);
if (hUpdateRes == NULL)
{
ErrorHandler("Could not open file for writing.");
}

// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes, // update resource handle
RT_DIALOG, // change dialog box resource
"AboutBox", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
ErrorHandler("Could not add resource.");
}

// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
ErrorHandler("Could not write changes to file.");
}

// Clean up.
if (!FreeLibrary(hExe))
{
ErrorHandler("Could not free executable.");
}

飘雪831101 2009-01-08
  • 打赏
  • 举报
回复
有用过BeginUpdateResource,这些的吗?请大家帮帮忙啊.
cnzdgs 2009-01-08
  • 打赏
  • 举报
回复
函数调用出错就用GetLastError取错误码,判断出错原因~
cnzdgs 2009-01-07
  • 打赏
  • 举报
回复
GetLastError
lizhigang34 2009-01-07
  • 打赏
  • 举报
回复
帮你查了下MSDN,不敢确认自己说的对不对:)

BeginUpdateResource
The BeginUpdateResource function returns a handle that can be used by the UpdateResource function to add, delete, or replace resources in an executable file.

大概的意思是:BeginUpdateResource返回一个能被UpdateResource函数添加,删除,或者替代资源的句柄..


BOOL UpdateResource(
HANDLE hUpdate, // update-file handle
LPCTSTR lpType, // resource type
.....)
第二个参数,资源类型中没有.exe,所以就返回NULL..
飘雪831101 2009-01-07
  • 打赏
  • 举报
回复
我用BeginUpdateResource("Comm.exe",FALSE)时,返回值总是为NULL,为什么啊?
它的第一个参数是什么的可执行文件啊?我一直不明白.

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧