Howdy, Stranger!

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

Categories

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!





Comments

  • Andre YoungAndre Young USAMember Posts: 0

    _________ / http://forcoder.org / free video tutorials and ebooks about \ Visual Basic C++ Assembly PHP JavaScript Python PL/SQL C# Java Delphi R MATLAB Go Scratch Perl Ruby C Visual Basic .NET Swift Objective-C Scheme Scala Dart Apex LabVIEW Crystal Hack Alice Awk F# FoxPro Bash SAS D Clojure VBScript Fortran Prolog COBOL ABAP Logo Rust Lisp Julia Erlang Transact-SQL ML Lua Ada Kotlin \

Sign In or Register to comment.