Passing var to C++ DLL from Delphi

Hi

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:
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API extern "C" __declspec(dllexport)
#else
#define TESTDLL_API extern "C" __declspec(dllimport)
#endif

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??

Thanks!





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!

Categories