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

发布于 2024-12-28 13:38:13 字数 1314 浏览 1 评论 0原文

我有一个旧的 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()< /code>

修饰名称是(使用 impdef 创建的 *.DEF 文件并使用依赖遍历器证明):

  • @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();

在 Booth 情况下,当我调用:

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

有什么问题吗?有人可以帮助我吗?

有趣的是,当我导入使用 Visual Studio C++ 创建的旧 dll 时,该函数的修饰名称是:_TestFunc1@0。这个名字与 Borland 的名字完全不同,但是很有效。

I have a old DLL (Borland Builder 2006 C++) which I want to use in .Net C# Visual Studio 2010. When I try to import the functions in VS always I get a StackOverflowException from Visual Studio. I've already read a lot stuff and the import seems to be easy. But I fail and don't see my error.

In the Borland DLL the Functions are exported as:

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

The decorated names are (*.DEF file created with impdef and proved with dependency walker):

  • @TestFunc1$qqsv
  • TestFunc2

In Visual Studio I import in this way:

[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();

In booth cases a get a StackOverflowException from Visual studio, when I call:

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

What is wrong ? Can anybody help me ?

Interesting when I import a old dll created with Visual Studio C++ the decorated name of the function is: _TestFunc1@0. The name is quite different to the Borland names but is works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

榆西 2025-01-04 13:38:13

正确的语法是:
extern "C" void __stdcall __declspec(dllexport) TestFunc1()

the correct syntax is:
extern "C" void __stdcall __declspec(dllexport) TestFunc1()

守望孤独 2025-01-04 13:38:13

我也有同样的问题。经过大量实验,我意识到问题不是语法问题。事实上,C++ Builder DLL 使用的是 VCL 表单。我删除了表格,一切正常。

I had the same problem. After a lot of experiments I realized that the problem was not a syntax one. It was the fact that the C++ Builder DLL was using VCL Forms. I removed the forms and everything worked.

做个少女永远怀春 2025-01-04 13:38:13

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

Yes, Panos seems to be right. I tried to P/Invoke an old BCB5 DLL with VCL and at the
first look it worked quite OK. But it silently has corrupted the C# program which manifests in strange exceptions a little bit later.
Not using the VCL in the Borland DLL was the only way to get it work. For us this means we have to convert our code to VisualStuidio which is on out todo-list anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文