Calling Delphi DLL from C# not passing integer correctly.

  • Thread starter Thread starter silentbazz
  • Start date Start date
S

silentbazz

I have method in a Delphi library (Delphi 2007) that is declared thus:

function ReturnValuation(OurRef : integer) : double; export;

In my C# console application (Visual Studio 2005, .NET 2.0) I use the
DLLImport attribute to declare this method:

[DllImport(@"C:\PP\AutoValLibrary.dll", EntryPoint =
"ReturnValuation", CallingConvention = CallingConvention.StdCall)]
public static extern double ReturnValuation(int OurRef);

In my C# code I do the following:

int OurRef = 829366;
progress = ReturnValuation(OurRef).ToString();

However when I get the Delphi DLL to output the integer that has been
passed in, I see that it thinks it has been passed 9539304.

Quite simply I am confused as to why this is happening, I have tried
to simplify what's passed into the DLL as I know there are issues with
certain types between C# and Delphi, but I honestly thought I'd be
okay with an integer?

Can anyone spot what might be wrong with my code
 
I have method in a Delphi library (Delphi 2007) that is declared thus:

function ReturnValuation(OurRef : integer) : double; export;

In my C# console application (Visual Studio 2005, .NET 2.0) I use the
DLLImport attribute to declare this method:

[DllImport(@"C:\PP\AutoValLibrary.dll", EntryPoint =
"ReturnValuation", CallingConvention = CallingConvention.StdCall)]
public static extern double ReturnValuation(int OurRef);

In my C# code I do the following:

int OurRef = 829366;
progress = ReturnValuation(OurRef).ToString();

However when I get the Delphi DLL to output the integer that has been
passed in, I see that it thinks it has been passed 9539304.

Quite simply I am confused as to why this is happening, I have tried
to simplify what's passed into the DLL as I know there are issues with
certain types between C# and Delphi, but I honestly thought I'd be
okay with an integer?

Can anyone spot what might be wrong with my code


How big is a Delphi integer? Maybe you need C# short, which is the same as
VB6 Integer?

Is Delphi using pass by value by default?
 
Integer in Delphi is a signed 32 bit number.

I don't recall, is there a way to explicitly tell Delphi to use StdCall on
that method, just to be sure?
 
Hi Peter,

Try this:

function ReturnValuation(i: integer): double; stdcall;

stcall is NOT the default in Delphi

Cheers
Doug Forster
 
Back
Top