Call Delphi DLL from C ++ \ CLI with many parameters

I have a Delphi 2010 DLL with two methods:

function Foo1(a, b: Integer):PChar; export; stdcall; function Foo2(a, b, c:Integer):PChar; export; stdcall; exports Foo1, Foo2; 

Each of them returns Result := PChar('Test') .

My C ++ \ CLI Code

in the title

 typedef const wchar_t* (*pFUNC1)(int a, int b); pFUNC1 TestFoo1; typedef const wchar_t* (*pFUNC2)(int a, int b, int c); pFUNC2 TestFoo2; 

Initialize with the LoadLibrary and GetProcAddress functions. Usage: TestFoo1(0,0) and TestFoo2(0,0,0) ;

Both work in Release mode.
But in debug mode, Foo2 is interrupted.

Please report what is wrong.

+7
source share
1 answer

Most likely you have a call agreement inconsistency. Change stdcall in Delphi to cdecl according to your C ++ / CLI code.

As an aside, you need to be careful about the lifetime of your strings if you try to return a value from a DLL that is not a literal stored in read-only memory in the data segment. But this is not a problem because PChar('Test') has the same lifetime as the DLL.

+4
source

All Articles