gpt4 book ai didi

c# - 调用可导出函数列表中的另一个函数

转载 作者:太空狗 更新时间:2023-10-29 23:50:59 24 4
gpt4 key购买 nike

我编写了一个库,其中包含一些正在导出的函数。一个例子:

[DllExport("Test", CallingConvention = CallingConvention.StdCall)]
public static void Test() {
MessageBox.Show("Test 1");
}

[DllExport("Test2", CallingConvention = CallingConvention.StdCall)]
public static void TestTwo() {
MessageBox.Show("Test 2");
Test();
//TestThree();
}

public static void TestThree() {
MessageBox.Show("Test 3");
}

当我从外部应用程序 (Delphi) 调用 Test 时,它工作正常并且我收到消息框。
当我调用 Test2 时,我在 Delphi 中得到了外部异常。立即抛出异常,它甚至不显示消息框 Test 2。当我调用 Test2 时,它又调用 TestThree,它不是可导出函数,它运行正常,我得到了消息框 Test 2测试 3

为什么我不能在我的 DLL 中调用其他导出的函数?有什么办法可以做到吗?

编辑 1:

在这一点上,我可以通过执行以下操作来实现我所需要的:创建了另一个不可导出的函数 Test_Local(),从 Test 中移动了所有代码。现在不是从 TestTwo 调用 Test() 我调用 Test_Local(),函数 Test 也调用 Test_Local();

一切运行正常,直到 Test_Local() 尝试运行任何其他可导出函数。

所以在另一个可导出函数中调用可导出函数在某种程度上是不好的,无论它们之间有多少层不可导出函数都没有关系。

最佳答案

我想到的一种可能性是该方法的导出名称和本地名称相同。您是否尝试过更改方法的本地名称?

[DllExport("Test", CallingConvention = CallingConvention.StdCall)]
public static void TestOne() {
MessageBox.Show("Test 1");
}

[DllExport("Test2", CallingConvention = CallingConvention.StdCall)]
public static void TestTwo() {
MessageBox.Show("Test 2");
TestOne();
//TestThree();
}

public static void TestThree() {
MessageBox.Show("Test 3");
}

我还没有测试过这个。

关于c# - 调用可导出函数列表中的另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26060184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com