繁体   English   中英

C#Windows窗体无法在Windows10上加载不受管理的C ++ DLL

[英]C# Windows Forms Unable to load unmanaged C++ DLL on Windows10

我有一个使用无人C ++ dll的C#Windows窗体应用程序。 当我调试或独立运行(在Windows7上)时,我只是将dll放在了应用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();

        }
}

如果要加载的DLL与可执行文件位于同一目录中,则将找到该文件。 这使我们得出结论,找不到的模块是您的DLL的依赖项。

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

  • 确保您运行的是发行版本而不是调试
  • 您可以通过在命令提示符下运行来确定dll依赖项:

    dumpbin / DEPENDENTS my.dll

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM