一个关于函数别名的问题

caike 2005-02-16 11:37:17
function _CreateMutex(lpMutexAttributes: PSecurityAttributes;
bInitialOwner: Integer; lpName: PChar): THandle; stdcall; external kernel32 name 'CreateMutexA';

function CreateMutex(lpMutexAttributes: PSecurityAttributes; bInitialOwner: BOOL; lpName: PChar): THandle;
begin
Result := _CreateMutex(lpMutexAttributes, Integer(Boolean(bInitialOwner)), lpName);
end;

function _CreateMutexA(lpMutexAttributes: PSecurityAttributes;
bInitialOwner: Integer; lpName: PAnsiChar): THandle; stdcall; external kernel32 name 'CreateMutexA';

function CreateMutexA(lpMutexAttributes: PSecurityAttributes; bInitialOwner: BOOL; lpName: PAnsiChar): THandle;
begin
Result := _CreateMutexA(lpMutexAttributes, Integer(Boolean(bInitialOwner)), lpName);
end;
================================
像上面这种情况,如果我调用CreateMutexA函数,是执行哪个呢?_CreateMutex和_CreateMutexA都是取别名CreateMutexA。
还想问一下,在单元中可以重新定义所引用的API函数吗?如上面两个程序段,就是重新定义了所引用的API函数?
...全文
90 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jadeluo 2005-02-16
  • 打赏
  • 举报
回复
问:像上面这种情况,如果我调用CreateMutexA函数,是执行哪个呢?
答:是_CreateMutexA。

问:_CreateMutex和_CreateMutexA都是取别名CreateMutexA。
答:这句话表达不正确。
正确表达是:在外部库kernel32中有一个名为CreateMutexA的函数,在这段代码中有两个这个外部函数的声明,一个是_CreateMutex,另一个是_CreateMutexA。
Bluekibo 2005-02-16
  • 打赏
  • 举报
回复
以上两个函数实际上是引用了同一个函数。
唯一不同的是参数形式,一个是BOOL,一个是Integer,
在实际中BOOL和Integer都是占4字节的内存,所以是一样的。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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