非托管出口 - DllExport和DllImport相撞?

时间:2014-03-04 15:08:43

标签: c# unmanaged

我正在测试Unmanaged Exports包。我创建了一个测试类:

public class TestClass
{
    [DllImport(@"SomeOther.dll")]
    private static extern int ProcessRequest(XmlDocument request, XmlDocument responce);

    [DllExport]
    public static int TestDLL(int x)
    {
        return x + 2;
    }

    [DllExport]
    public static int TestRequest(XmlDocument request, XmlDocument responce)
    {
        //ProcessRequest(ref request, ref responce);
        return 0;
    }
}

然后我构建它并使用dumpbin / exports进行测试,以查看我的函数是否真的可见。 对于上面的代码,我只在输出中得到一个函数:

  ordinal hint RVA      name
        1    0 000027CE TestRequest

如果我改变班上方法的顺序:

public class TestClass
{
    [DllImport(@"SomeOther.dll")]
    private static extern int ProcessRequest(XmlDocument request, XmlDocument responce);

    [DllExport]
    public static int TestRequest(XmlDocument request, XmlDocument responce)
    {
        //ProcessRequest(ref request, ref responce);
        return 0;
    }

    [DllExport]
    public static int TestDLL(int x)
    {
        return x + 2;
    }
}

dumpbin的输出更改为:

  ordinal hint RVA      name
        1    0 000027CE TestDll

最后,如果我在导出的方法之后放入DllImport部分,我最终会得到:

   ordinal hint RVA      name
         1    0 0000276E TestRequest
         0    1 0000275E TestDLL

为什么会这样?我的代码中有错误吗?

0 个答案:

没有答案