Unable to load Win32 Native DLL file from C#.NET

血红的双手。 提交于 2019-12-25 16:58:47

问题


I have a C# winapp. I call a native .dll file (created in C++ by myself) from the C# app, and it works fine.

But when I copy my application (.exe and .dll files) to another machine, I get an error that says:

Unable to load DLL "c:\dllname.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Here is the C# code:

class IsoMessageHelper
{
    public const string ISO8583_DLL = "c:\\Hc8583.dll";
    [DllImport(ISO8583_DLL, CallingConvention = CallingConvention.Cdecl)]
    public static extern bool InitializationRq(...)
}

What should I do?


回答1:


A common issue when deploying .Net applications that have native dependencies, is that the native dlls may be missing dependencies themselves on the target machines e.g. the correct version of the C runtime.

Use a tool such a Dependency Walker to analyze your native dll and determine if it has a missing dependency on the machine you have copied it too.




回答2:


Try not to hard code any paths in the DllImport attribute parameter that specifies the name of the file. Then you should make usre the file is right besides the executable.

Something like this:

[DllImport("user32.dll", CharSet = CharSet.Unicode)]



回答3:


Move the DLL to the root. If that works, then look at your attribute to determine why. You haven't posted any code, so I can't give you any specific reason.



来源:https://stackoverflow.com/questions/4655294/unable-to-load-win32-native-dll-file-from-c-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!