C#.Net中使用的Borland Builder 2006 DLL-System.StackOverflowExcep

本文关键字:Builder 2006 DLL-System StackOverflowExcep Borland Net | 更新日期: 2023-09-27 18:21:12

我有一个旧的DLL(Borland Builder 2006 C++),我想在.Net C#Visual Studio 2010中使用它。当我试图在VS中导入函数时,我总是从Visual Studio中得到StackOverflowException。我已经读了很多东西,导入似乎很容易。但我失败了,没有看到我的错误。

在Borland DLL中,函数导出为:

  • __declspec(dllexport) void TestFunc1()
  • extern "C" __declspec(dllexport) void __stdcall TestFunc2()

修饰的名称是(使用impdef创建的*.DEF文件,并使用依赖项walker进行验证):

  • @TestFunc1$qqsv
  • TestFunc2

在Visual Studio中,我以这种方式导入:

[DllImport("MyDllName.dll", EntryPoint = "@TestFunc1$qqsv", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
public static extern void TestFunc1();
[DllImport("MyDllName.dll",CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
public static extern void TestFunc2();

在展台的情况下,当我调用时,会从Visual studio获得StackOverflowException

  • MyImport_Unmanaged.TestFunc1()
  • MyImport_Unmanaged.TestFunc2()

怎么了?有人能帮我吗?

有趣的是,当我导入一个用Visual Studio C++创建的旧dll时,函数的修饰名称是:_TestFunc1@0。这个名字与Borland的名字大不相同,但却是可行的。

C#.Net中使用的Borland Builder 2006 DLL-System.StackOverflowExcep

正确的语法是:extern"C"void__stdcall__declspec(dllexport)TestFunc1()

我也遇到了同样的问题。经过大量的实验,我意识到这个问题不是语法问题。事实上,C++Builder DLL使用的是VCL窗体。我去掉了表格,一切都好了。

是的,帕诺斯似乎是对的。我尝试用VCL P/Invoke一个旧的BCB5 DLL乍一看,它运行得很好。但它悄悄地破坏了C#程序,稍后会出现奇怪的异常。在Borland DLL中不使用VCL是使其工作的唯一方法。对我们来说,这意味着我们必须将代码转换为VisualStuidio,它无论如何都在待办事项列表中。