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

时间:2014-09-26 12:58:30

标签: c# dll dllexport

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

[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中获得了External异常。异常被立即抛出,它甚至没有显示消息框Test 2。 当我拨打Test2时调用TestThree,这不是可导出的功能,它运行正常,我同时收到消息框Test 2Test 3

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

编辑1:

此时我可以通过以下方式实现我所需要的: 创建了另一个不可导出的函数Test_Local(),移动了Test的所有代码。现在,Test()调用TestTwo而不是从Test_Local()拨打Test来调用Test_Local();

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

因此,在另一个可导出函数中调用可导出函数是不合适的,并且它们之间有多少层不可导出的函数并不重要。

1 个答案:

答案 0 :(得分:0)

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

[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");
}

我没有测试过这个。