为什么不成功?帮帮忙。(25分)

  • 主题发起人 主题发起人 you_known
  • 开始时间 开始时间
Y

you_known

Unregistered / Unconfirmed
GUEST, unregistred user!
我在MSDN上找到有关资源替换的源代码,将它翻译成Delphi,但是无法成功。
不知道是哪里有问题?各位帮帮忙看看,谢谢了。
====Delphi============================================================
function MakeLangID(PrimaryLanguage,SubLanguage : word) : DWord;
begin
Result:=SubLanguage shl 10;
Result:=Result or PrimaryLanguage;
end;

procedure change;
var
hResLoad:HRSRC; // handle to loaded resource
hExe:THANDLE; // handle to existing .EXE file
hRes:HRSRC; // handle/ptr. to res. info. in hExe
hUpdateRes:THANDLE; // update resource handle
lpResLock:^char; // pointer to resource data
return:BOOL;
begin
hExe := LoadLibrary('D:/M.exe');
if hExe=0 then messagebox(0,'error open exe','error',0);

hRes := FindResource(hExe, 'MAINICON', RT_ICON);
if hRes=0 then messagebox(0,'can not find ico','error',0);

hResLoad:= LoadResource(hExe, hRes);
if hResLoad=0 then messagebox(0,'Load error','error',0);

lpResLock:= LockResource(hResLoad);
if lpReslock=nil then messagebox(0,'can not lock resource','error',0);

hUpdateRes:= BeginUpdateResource('d:/P.exe', FALSE);
if hUpdateRes=0 then messagebox(0,'can not open file for write','error',0);

return:= UpdateResource(hUpdateRes, // update resource handle
RT_ICON, // change Icon resource
'MAINICON', // Icon name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if return=false then messagebox(0,'can not add res','error',0);

if (not EndUpdateResource(hUpdateRes, FALSE)) then messagebox(0,'can not make change','error',0);

if (not FreeLibrary(hExe)) then messagebox(0,'can not free exe','error',0);
end;
======================================================================
下面是C的源代码:
====C/C++=============================================================
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.");
}

 
What is the error code or error message!
 
varphone,没有错误信息,只是功能没有实现,无法替换图标
 
varphone,
程序执行到hUpdateRes:= BeginUpdateResource('d:/P.exe', FALSE);这一行,无法得到
正确的句柄。为什么?
 
What is your platform!
To use BeginUpdateResource() must in WinNT or Win2000 or WinXp!
 
varphone,
我用的是Windows Me。
那有没有别的办法实现我要的功能呢?
 
delphi与vc的资源保存方式是不同的,不知有没有关系!!??
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=555645
 
接受答案了.
 
后退
顶部