Delphi和C++相互调用归纳

Calling conventions

Directive

Parameter order

Clean-up

Passes parameters in registers?

register

Left-to-right

Routine

Yes

pascal

Left-to-right

Routine

No

cdecl

Right-to-left

Caller

No

stdcall

Right-to-left

Routine

No

safecall

Right-to-left

Routine

No

使用 stdcall 方式是一种比较好的选择。

Delphi

引入

procedure Foo(...); stdcall; external 'foo.dll';

引出

procedure Foo(...); export; stdcall;

dpr 文件的“ {$R *.res} ”和“ begin end. ”之间加上

exports

  Foo;

C++

引入

typedef void (_stdcall *FOO)(...);

FOO Foo;

HMODULE hDll = LoadLibrary("foo.dll");

Foo = (FOO)GetProcAddress(hDll, "Foo");

...;

FreeLibrary(hDll);

引出

void _stdcall Foo(...);

def 文件中导出符号。详见“ DLL 专题 .txt ”。

例如:

lib.def

LIBRARY LIB

EXPORTS

add @ 1

 

lib.h

int _stdcall add(int x,int y);

 

lib.cpp

BOOL APIENTRY DllMain(...)

{

...

}

 

int _stdcall add(int x,int y)

{

    return x + y;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值