两段几乎相同的代码,pascal代码运行后成功更改了资源句柄, c++代码却不行,不得其解?

kmfangxun 2006-09-18 11:23:56
//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编译。

...全文
257 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
netliuming 2006-09-21
  • 打赏
  • 举报
回复
不明白!!
这个结构不是bcb自身包含的吗?
struct PACKAGE TLibModule
{
TLibModule *next;
long instance;
long codeinstance
long datainstance
long resinstance;
long reserved;
};
extern PACKAGE TLibModule *LibModuleList;
难道是bcb弄错了,能解析一下吗? Delphi转BCB的时候遗漏TLibModule类型.

王集鹄 2006-09-21
  • 打赏
  • 举报
回复
原贴:

将Delphi和BCB声明比较就知道问题了
type
PLibModule = ^TLibModule;
TLibModule = record
Next: PLibModule;
Instance: LongWord;
CodeInstance: LongWord;
DataInstance: LongWord;
ResInstance: LongWord;
Reserved: Integer;
end;


struct PACKAGE TLibModule
{
TLibModule *next;
long instance;
long resinstance;
long reserved;
};

Delphi转BCB的时候遗漏TLibModule类型,汗
kmfangxun 2006-09-21
  • 打赏
  • 举报
回复
呵呵,终于在Delphi区找到答案!


http://community.csdn.net/Expert/topic/5036/5036288.xml?temp=.9968988
王集鹄 2006-09-21
  • 打赏
  • 举报
回复
to netliuming
两边声明不一致

CurModule->resinstance = NewInstance;
实际上是
CurModule->CodeInstance = NewInstance;

难道你的BCB已经打了补丁?这段声明在哪一个文件?
CACACACACA 2006-09-19
  • 打赏
  • 举报
回复
mark
kmfangxun 2006-09-18
  • 打赏
  • 举报
回复
to netliuming

没有效果。


难道Pascal 的Result被赋值后还作了什么吗?
netliuming 2006-09-18
  • 打赏
  • 举报
回复
试试将long改成Cardinal或int不知是否有效?
kmfangxun 2006-09-18
  • 打赏
  • 举报
回复
检查运行后资源句柄是否更改:


//放在c++ return Result
HINSTANCE Hres=(HINSTANCE)FindResourceHInstance((long)HInstance);

if(Hres==(HINSTANCE)Result)
ShowMessage("Changed");
else
ShowMessage("UnChanged");

kmfangxun 2006-09-18
  • 打赏
  • 举报
回复
我是把例子中Reinit.pas改成了C++,其它地方都没有问题,只有列出的代码部分运行后效果不一致。
Y___Y 2006-09-18
  • 打赏
  • 举报
回复
帮顶
i_love_pc 2006-09-18
  • 打赏
  • 举报
回复
学习一下.
kmfangxun 2006-09-18
  • 打赏
  • 举报
回复
楼上看看Cbuilder6的Example\apps\RichEdit就知道了。
我来看看CB 2006-09-18
  • 打赏
  • 举报
回复
看不明白
kmfangxun 2006-09-18
  • 打赏
  • 举报
回复
To: MEFULEU

还是不行。加了 extern PACKAGE int HInstance后;

不得不改为:
if ( CurModule->instance==(long)Sysinit::HInstance )

编译通过,运行后没有需要的效果。
MEFULEU 2006-09-18
  • 打赏
  • 举报
回复
extern PACKAGE int HInstance;


if (int(CurModule->instance) ==HInstance )

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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