Howdy, Stranger!

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


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



  • Andre YoungAndre Young USAMember Posts: 0

    _________ / / 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.