C#Windows窗体无法在Windows10上加载非托管C ++ DLL

时间:2016-01-28 09:05:01

标签: c# c++ winforms dll dllimport

我有一个使用无人c ++ dll的C#Windows窗体应用程序。 当我调试或运行它作为独立的(在windows7上)时,我只是将dll放在app exe旁边,它运行得很好。

当我尝试在Windows10上执行相同操作(独立运行)时,我得到以下异常:

Unable to load DLL 'AnalyzerLib.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

谁能告诉我为什么?我应该在某个地方给予许可还是注册?

以下是我从代码访问dll的方法:

namespace Analyzer {
public unsafe class Connector {
    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    public static extern bool isAvailable();

    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    public static extern void win32set_DetectParams(float[] parameters, int prob_Size);

    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    public static extern void win32setDetectParamsAndColorMatrix(float[] parameters, int prob_Size, float[] colorMatrix16bytes);

    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    public static extern void win32analyzeBuffer(byte[] javaBuffer, byte[] javaInputCopyBuffer, int[] analyzeBufferResArr, int width, int height, bool convertYUV2RGB);

    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    public static extern int getCoreLogBufferSize();

    [DllImport("AnalyzerLib.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
    private static extern byte* getCoreLogBuffer();

        }
}

1 个答案:

答案 0 :(得分:0)

如果要加载的DLL与可执行文件位于同一目录中,则会找到它。这导致我们得出结论,无法找到的模块是您的DLL的依赖项。

通常这意味着您需要安装DLL所依赖的相应MSVC运行时。

  • 确保您运行发布版本而不是调试
  • 您可以通过从提示命令运行来找出dll依赖项:

    dumpbin / DEPENDENTS my.dll