0

我已经为 windows mobile SDK 编译了一个本机 dll,然后创建了 c# 项目来调用它。但是,我得到的只是一个 MissigMethodException。

Dll 与托管可执行文件位于同一文件夹中。

以下是导出函数在标题中的外观:

namespace cuttingStream
{
    /**
     * Открывается файл и производится его проверка.
    **/
    __declspec(dllexport) bool open_png_file(char* , pngDataStructures* );
    __declspec(dllexport) void close_png_file(pngDataStructures*);
    ...
}

这是我导入它们的方式:

static class CuttingStreamWrapper
{
    [DllImport("libpngStreamWrap.dll", EntryPoint = "open_png_file")]
    public static extern bool OpenPngFile(string fileName, out pngDataStructures dataStruct);
    [DllImport("libpngStreamWrap.dll", EntryPoint = "close_png_file")]
    public static extern bool ClosePngFile(ref pngDataStructures dataStruct);
}

这是dumpbin的输出(相关部分):

1    0 00001340 ?close_png_file@cuttingStream@@YAXPAUpngDataStructures@@@Z
2    1 00001194 ?open_png_file@cuttingStream@@YA_NPADPAUpngDataStructures@@@Z

在源文件和头文件中标记函数后extern "C",dumpbin 输出变为:

ordinal hint RVA      name

      1    0 00001314 close_png_file
      2    1 0000118C open_png_file

这似乎没有被破坏。

但是,问题仍然存在。这是我收到的例外情况:

System.MissingMethodException was unhandled
  Message="Не удается найти PInvoke DLL \"libpngStreamWrap.dll\"."

StackTrace 仅具有程序的主要功能,我尝试在其中调用包装函数。

更新:

在我试图加载的 dll 上运行依赖 walker 后,我有 2 个依赖项:Coredll.dll、msvcr90d.dll。在我试图部署到那里的设备上只有 msvcr80.dll。这解释了加载失败。

4

1 回答 1

2

问题的根源在于 dll 对 msvcr90d.dll 的依赖,这在设备上找不到。一旦消除了依赖关系(通过从 /MDd 切换到 /MTd),就找到了 dll。

于 2012-10-18T11:58:29.123 回答