C#兼容类型在Delphi中为double [英] C# compatible type for double in Delphi

查看:87
本文介绍了C#兼容类型在Delphi中为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个Delphi构建的DLL,其中包含一个函数,该函数采用数据类型为double的参数.我需要从C#代码中调用此函数.以下是代码:-

 [DllImport(" ,CallingConvention = CallingConvention.StdCall)]
      公共 静态 外部  Double  x,字符串 printText, Int32  scriptCode); 



函数调用就像:-

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


在哪里,X& Y是双& strTextToPrint,iScriptCode是字符串& Int32响应.

调用该函数时,出现异常检测到PInvokeStackImbalance".有关更多信息,说明托管PInvoke签名与非托管目标签名不匹配.

Int32&字符串数据类型可用于其他dll函数调用.但是我不确定用于double的数据是什么?我也尝试过float,但同样的错误即将到来.

任何帮助将不胜感激.谢谢.

问候,
Saurabh.

解决方案

看起来像是Single而不是double.

第1.2节建议: http://ultrastardeluxe.xtremeweb-hosting.net/wiki /doku.php?id=development:c_header_conversion [ ^ ]


自1990年以来我还没有做过帕斯卡,所以认为这是一个WAG ...

Delphi使用real类型(及其变体),. Net具有floatdouble.既然您已经尝试过double,请尝试使用float代替,看看是否可行.

您的问题也可能集中在字符串参数周围. .Net中没有Delphi的字符串对象的等效项,除非您调用的方法使用PAnsiCharPWideChar类型的字符串参数.
顺便说一句,我在Google上找到了所有这些信息.无疑这将是艰难的搜索,但是我想您可能会在这里找到答案.

双向都兼容.


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

[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.

解决方案

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[^]


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.


Probably you should accept PChar parameter rather than string parameter to become compatible with .NET.

Double is compatible in both sides.


这篇关于C#兼容类型在Delphi中为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆