两段几乎相同的代码,pascal代码运行后成功更改了资源句柄, c++代码却不行,不得其解?
//pascal代码,运行后成功更改了资源句柄
function SetResourceHInstance(NewInstance: Longint): LongInt;
var
CurModule: PLibModule;
begin
CurModule := LibModuleList;
Result := 0;
while CurModule <> nil do
begin
if CurModule.Instance = HInstance then
begin
if CurModule.ResInstance <> CurModule.Instance then
FreeLibrary(CurModule.ResInstance);
CurModule.ResInstance := NewInstance;
Result := NewInstance;
Exit;
end;
CurModule := CurModule.Next;
end;
end;
///c++代码,运行后资源句柄没有变化
long int __fastcall SetResourceHInstance(long int NewInstance)
{
long int Result;
TLibModule *CurModule;
CurModule = LibModuleList; //
Result = 0;
while( CurModule != NULL )
{
if (CurModule->instance ==(long) HInstance )
{
if(CurModule->resinstance != CurModule->instance)
FreeLibrary((HINSTANCE)CurModule->resinstance);
CurModule->resinstance = NewInstance;
Result = NewInstance;
break;
}
CurModule = CurModule->next;
}
return Result;
}
//------------------------------------------------------------------------------
两段代码均用Cbuilder6编译。