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

本文关键字:加载 DLL C++ Windows10 窗体 Windows | 更新日期: 2023-09-27 18:32:11

我有一个使用无人 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();
        }
}

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

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

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

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

    垃圾箱/家属我的.dll