非托管导出System.MissingMethodException

时间:2018-08-31 10:13:52

标签: c# missingmethodexception unmanagedexports

我有两个使用UnmanagedExports公开的函数getStatus()和checkStatus()。我可以成功地将它们与C ++代码分开调用。但是,当我从第二个函数checkStatus()中调用第一个函数getStatus()时,我得到了MissingMethodException。下面的独立函数代码可以正常工作:

[DllExport(ExportName = "GetStatusMethod", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string getStatus([MarshalAs(UnmanagedType.LPWStr)]string Url)
{
    string status;
    //performing some action
    return status;
}

[DllExport(ExportName = "CheckStatusMethod", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string checkStatus([MarshalAs(UnmanagedType.LPWStr)]string someStr)
{
    string status;
    //performing some action
    return status;
}

以下引发MissingMethodException:

[DllExport(ExportName = "GetStatusMethod", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string getStatus([MarshalAs(UnmanagedType.LPWStr)]string Url)
{
    string status;
    //performing some action
    return status;
}

[DllExport(ExportName = "CheckStatusMethod", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string checkStatus([MarshalAs(UnmanagedType.LPWStr)]string someStr)
{
    return getStatus();// throws MissingMethodException
}

如何在c#中的另一个公开函数中调用一个函数(使用UnmanagedExports公开)?

0 个答案:

没有答案