C# Windows 表单无法在 Windows10 上加载非托管 C++ DLL
C# Windows Forms Unable to load unmanaged C++ DLL on Windows10
我有一个使用无人 C++ dll 的 C# Windows Forms 应用程序。
当我调试时,或 运行 它作为独立的(在 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 的依赖项。
通常这意味着您需要安装适当的 MSVC 运行您的 DLL 所依赖的时间。
- 确保你 运行 是发布版本而不是调试
您可以通过 运行ning 从命令提示中找出 dll 依赖关系:
dumpbin/家属my.dll
我有一个使用无人 C++ dll 的 C# Windows Forms 应用程序。 当我调试时,或 运行 它作为独立的(在 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 的依赖项。
通常这意味着您需要安装适当的 MSVC 运行您的 DLL 所依赖的时间。
- 确保你 运行 是发布版本而不是调试
您可以通过 运行ning 从命令提示中找出 dll 依赖关系:
dumpbin/家属my.dll