开发者

Reference parameters in Delphi to C++ DLL

开发者 https://www.devze.com 2023-03-31 15:43 出处:网络
I\'m creating a DLL in Delphi that must have the following C++ structure. DWORD Load(char* &Test);

I'm creating a DLL in Delphi that must have the following C++ structure.

DWORD Load(char* &Test);

So the test must be a reference parameter. I tried '开发者_JS百科var' and 'out' in Deplhi, but I get an error in my C++ application that uses the DLL.


A literal translation of that code is this:

function Load(var Test: PAnsiChar): DWord; cdecl;

Notice the calling convention. If you're missing that, then Delphi places the first parameter in a register, but the C++ code expects it on the top of the stack.


Like 'Rob Kennedy' stated, it must have 'cdecl'. I fixed the problem by using that. Here is the fixed code

function Load(out Test : PAsniChar) : Integer; cdecl ; export;
begin
  Test := 'Test String';
end;

Thanks for the help!

0

精彩评论

暂无评论...
验证码 换一张
取 消