调用dll函数时出现SEHException [英] SEHException while calling dll function

查看:112
本文介绍了调用dll函数时出现SEHException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在从C#中调用Delphi dll中的函数. "System.Runtime.InteropServices.SEHException发生在transliteration.exe中.
附加信息:外部组件已引发异常".

dll中的函数签名如下:

Hi all,
I am calling a function in Delphi dll from C#.I am getting an exception saying
"System.Runtime.InteropServices.SEHException occurred in transliteration.exe.
Additional information:External componenet has thrown an exception".

Function signature in dll is like this:

FUNCTION foo(PASS1,PASS2 : LongInt; Astring, BString : PChar; Scrpt : LongInt) : LongInt; stdcall;EXPORT;


& C#中对应的签名是-


& corresponding signature in C# is -

public static extern int foo(Int32 pass1, Int32 pass2, string txtToConvert, StringBuilder convText, ref Int32 scriptCode);


该函数在文本框离开事件上调用.我需要通过引用传递C#中的最后一个参数.如果没有,我会收到访问冲突异常.知道这与Program.cs中的Application.EnableVisualStyles();函数有关(我不确定).这是真的还是其他解决方案?

相同的功能在我这边起作用,但是在客户端计算机上却给出了例外.计算机配置完全相同.

请帮帮我.
谢谢.


The function is called on textbox leave event.I need to pass last parameter in C# by reference.If i don''t I get an access violation exception.I surfed the internet about this exception & got to know that this is related to Application.EnableVisualStyles(); function in Program.cs (I am not sure about this.)Is it true or is there is any other solution for this?

The same function is working on my side but on client''s machine its giving an exception.Machine configuration is exactly same.

Please help me.
Thanks.

推荐答案

C#函数不对应于Delphi.怎么可能是StringBuilder?最后一个参数不是通过引用而是通过值.

试试
The C# function is not corresponding to the Delphi one. How can it be StringBuilder, ever? Last parameter is not by ref but by value.

Try
public static extern Int32 foo(
    Int32 pass1, Int32 pass2,
    string txtToConvert, string convText,
    Int32 scriptCode);



我不太确定PChar类型的参数之一.如果要输出其中一个参数,则可能两个签名都不正确.

如果最后一个参数应通过引用,则在Delphi中可以为varconst(是的,Delphi具有怪异的功能:在参数前的const表示常量引用",而不仅仅是常量),在C#中应该为outref(它仅取决于函数实现的语义并影响调用方的用法).

—SA



I''m not really sure about one of the parameters of the type PChar. If one of the parameters is meant to be output, probably both signatures are incorrect.

If last parameter should be by reference, it could be var or const in Delphi (yes, Delphi has a weird feature: const before a parameter means "constant reference", not just constant), and in C# in should be out or ref (it only depends on function implementation semantic and affects the usage by the caller).

—SA


您必须使用PInvoke才能使用非托管类型(如.NET中的PChar)来调用此类DLL.这些链接将非常有用:

http://embarcadero.newsgroups.archived.at/public.delphi.nativeapi/201007/1007013727.html [ ^ ]

http://msdn.microsoft.com/de-de/library/system. runtime.interopservices.unmanagedtype.aspx [ ^ ]
You must use PInvoke to use unmanaged types like PChar in .NET to call such DLLs. These links would be useful:

http://embarcadero.newsgroups.archived.at/public.delphi.nativeapi/201007/1007013727.html[^]

http://msdn.microsoft.com/de-de/library/system.runtime.interopservices.unmanagedtype.aspx[^]


这篇关于调用dll函数时出现SEHException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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