Passing var to C++ DLL from Delphi


I am trying to use a C++ DLL in Delphi. I can load the function from the dll, and can even pass data from the dll to delphi. But when i pass data to the function's parameter, it gets random data from mem. Does anyone know how to fix this?

Here is code snippets:
// in TestDLL.h:
#define TESTDLL_API extern "C" __declspec(dllexport)
#define TESTDLL_API extern "C" __declspec(dllimport)

TESTDLL_API int Multiply(int num);

// --- in TestDLL.cpp:
TESTDLL_API int Multiply(int num)
return num*2;

// In delphi i load function like this:
function Multiply(num:integer):integer; external 'testdll.dll';

// And use it like:
Label1.Caption := IntToStr(Multiply(5));

if I return , say 5, from the Multiply function, delphi can see it, but if I pass 5 to the function, I get like for example 1243560.

what is wrong??


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!