Click here to Skip to main content
15,888,186 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
Hi all,
I have a Delphi built DLL contaning a function which takes a argument having data type as double. I need to call this function from C# code.Here is the code:-

C#
[DllImport("C:\\Smhita20\\Dmp.dll",CallingConvention = CallingConvention.StdCall)]
      public static extern void PRINT_DOC(Double x, Double y, string printText, Int32 scriptCode);


And function call is like:-

Dmp.PRINT_DOC(X, Y, strTextToPrint, iScriptCode);

where, X & Y are double & strTextToPrint,iScriptCode are string & Int32 resp.

While calling the function I am getting the exception "PInvokeStackImbalance was detected".More info on this says that managed PInvoke signature does not match the unmanaged target signature.

Int32 & string data types are working for other dll function calls.But I am not sure about what to use for double? I tried float also but same error is coming.

Any help would be appreciated.Thanks.

Regards,
Saurabh.
Posted
Updated 10-Feb-11 0:32am
v3

Looks like it is a Single rather than a double.

Section 1.2 sort of suggests that: http://ultrastardeluxe.xtremeweb-hosting.net/wiki/doku.php?id=development:c_header_conversion[^]
 
Share this answer
 
Comments
bsaurabh 10-Feb-11 2:58am    
Hey,thanks for reply.
As per your suggestion & article I tried with the Single.
Its giving me the access violation exception...
Could there be another solution? Now,I have done with all floating point types in c# ie float,double & single.
I haven't done pascal since 1990, so consider this to be a WAG...

Delphi uses the real type (and variants of it), and .Net has float and double. Since you've already tried double, try using float instead and see if that works.

Your problem may also be centered aroundf the string parameter. There is no equivalent for Delphi's string object in .Net unless the method you're calling is using string parameters of type PAnsiChar or PWideChar.

BTW, I found all this info on google. It's going to be an admittedly tough search, but I think you might find your answer there.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-Feb-11 13:47pm    
John, Real is a bad Delphi type, normally people use "double" and "extended". Double is double.
(I've done Delphi by 2004 or so...)
As far as I remember, Real is intermediate precision not supported by CPU (introduced when math co-processors were emerging, so it is emulated type.
--SA
bsaurabh 10-Feb-11 3:02am    
Thanks for reply John.
I have already tried using float but it is not working.
And I am sure about string parameter.It is correct & problem certainly revolves around the float/double.
Probably you should accept PChar parameter rather than string parameter to become compatible with .NET.

Double is compatible in both sides.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900