开发者

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

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 tha开发者_C百科t 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?


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.


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)]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜