简体   繁体   English

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

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

I have a C# Windows Forms Application that use an unmanned c++ dll. 我有一个使用无人C ++ dll的C#Windows窗体应用程序。 When when I debug, or run it as standalone (on windows7), I just put the dll next to the app exe and it runs great. 当我调试或独立运行(在Windows7上)时,我只是将dll放在了应用exe旁边,因此运行效果很好。

When I try to do the same on Windows10 (run as standalone) I get the following exception: 当我尝试在Windows10上执行相同操作(独立运行)时,出现以下异常:

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

Can anyone tell me why? 谁能告诉我为什么? should I give a permission somewhere or register it? 我应该在某个地方授予许可还是进行注册?

Here is how I access the dll from code: 这是我从代码访问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();

        }
}

If the DLL you are loading is in the same directory as the executable, then it will be found. 如果要加载的DLL与可执行文件位于同一目录中,则将找到该文件。 Which leads us to conclude that the module(s) that cannot be found are your DLL's dependencies. 这使我们得出结论,找不到的模块是您的DLL的依赖项。

Normally this means that you need to install the appropriate MSVC runtime upon which your DLL depends. 通常,这意味着您需要安装DLL所依赖的适当的MSVC运行时。

  • Make sure the you run the release version and not the debug 确保您运行的是发行版本而不是调试
  • You can figure out the dll dependencies by running from command prompted: 您可以通过在命令提示符下运行来确定dll依赖项:

    dumpbin /DEPENDENTS my.dll dumpbin / DEPENDENTS my.dll

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

相关问题 aspnet 应用程序无法在 windows10/iis10 中加载非托管 dll - aspnet application unable to load unmanaged dll in windows10/iis10 无法在Windows 7 32位操作系统的C#应用​​程序中加载C ++ DLL - Unable to load C++ DLL in C# application in Windows 7 32 bit OS Windows 8/10上的Unity3D C ++非托管DLL崩溃,适用于7 - Unity3D C++ unmanaged DLL crash on windows 8/10, works on 7 通过C#Net Core的非托管C ++ DLL订阅Windows消息 - Subscribing to windows messages through unmanaged c++ dll from c# net core 从两个不同的应用程序(ac#Windows服务和一个软件平台)访问c ++中的非托管dll - access unmanaged dll in c++ from two different applications (a c# windows service and a software platform) 从C#windows服务调用C ++ DLL(非托管代码)(用托管代码编写) - Calling a C++ dll (unmanaged code) from a C# windows service (written in managed code) 在Windows Mobile中将C#字符串传递给非托管C DLL - Passing a C# string to an unmanaged C DLL in Windows Mobile 点击事件处理程序C#Windows10 - tapped event handler c# windows10 C# - 检查 Windows10 上是否安装了 UWP 应用 - C# - Check if a UWP app is installed on Windows10 C# dll 调用 C++ dll 在 Windows 10 上找不到 dll - C# dll calling a c++ dll cannot find the dll on windows 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM