Visual C++ 使用哪种调用约定来调用 Delphi 编写的 DLL 函数?

问题描述 投票:0回答:1

我正在使用Delphi XE3写一个函数,如下:

function CheckLicense(const lpszAppName: PChar): Integer; stdcall;
begin
...
end;

exports
   CheckLicense;

那我应该在Visual C++中使用

CALLBACK
来调用它吗:

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

    typedef INT (CALLBACK* CHECKLICENSEPROC)(LPCTSTR lpszAppName);

#ifdef __cplusplus
}
#endif

或者用

__stdcall
代替?

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

    typedef INT (__stdcall* CHECKLICENSEPROC)(LPCTSTR lpszAppName);

#ifdef __cplusplus
}
#endif

正确吗?

c++ delphi
1个回答
0
投票

CALLBACK
只是
__stdcall
的别名。与
WINAPI
也一样。但是,由于您导出的函数不是回调函数,因此从语义角度来看,我不建议使用
CALLBACK
,而是直接使用
WINAPI
__stdcall
。其实这并不重要。

此外,

LPCTSTR
是第一个参数使用的错误类型。该类型根据项目设置在
const char*
const wchar_t*
之间切换,但 Delphi 2009 及更高版本中的
PChar
严格仅限于
wchar_t*
,因此请使用
LPCWSTR
(又名
const wchar_t*
)。

© www.soinside.com 2019 - 2024. All rights reserved.