简体   繁体   English

无法在C#中加载64位dll错误

[英]Unable to load 64-bit dll Error in C#

I have 64-bit c++ ddl, which I have to use in my c# application. 我有64位c ++ ddl,必须在我的c#应用程序中使用。 I used it like 我用它像

[DllImport("sampleDll.dll",
    EntryPoint = "sampleFunction",
    CharSet = CharSet.Ansi,
    CallingConvention = CallingConvention.StdCall)]
    public static extern int sampleFunction(char[] ch, int i);

But when i try to run the application it shows error as 但是当我尝试运行该应用程序时,它显示错误为

"Unable to load DLL 'sampleDll.dll': The specified module could not be found." “无法加载DLL'sampleDll.dll':找不到指定的模块。”

Iam using 64-bit OS. Iam使用64位操作系统。 I tried by copying the dll into System32 folder 我尝试将dll复制到System32文件夹中

But still Iam getting the same error. 但是我仍然遇到相同的错误。

Please let me know the workaround for this problem........ 请让我知道此问题的解决方法........

I'm going to assume that your C# process is 64 bit. 我将假设您的C#进程是64位。 If it's a 32 bit process, then you cannot load a 64 bit DLL, and that's the reason for the failure. 如果是32位进程,则无法加载64位DLL,这就是失败的原因。

If you copied the file into system32 then a 64 bit process will look there. 如果将文件复制到system32则将在其中查找64位进程。 If the file you copied is named sampleDll.dll , then your program will find it. 如果您复制的文件名为sampleDll.dll ,则程序将找到它。 So, if you see 所以,如果你看到

Unable to load DLL 'sampleDll.dll': The specified module could not be found.

the problem is not that sampleDll.dll cannot be located, rather that its dependencies cannot be resolved. 问题不在于无法sampleDll.dll ,而是无法解决其依赖性。 The most common explanation for this is that you need to install the C runtime that sampleDll.dll depends upon. 对此的最常见解释是,您需要安装sampleDll.dll依赖的C运行时。 Consult the documentation for this DLL to find out what its dependencies are. 请查阅此DLL的文档,以了解其依赖性。 If it's a DLL that you have made yourself, then you know what you used when you built it and can discern the dependencies for yourself. 如果它是您自己创建的DLL,则您知道构建它时使用的内容,并且可以自己识别依赖项。

Finally, I would stress that you should not be copying files into the system32 directory. 最后,我要强调的是,您不应将文件复制到system32目录中。 That belongs to the system and you should not touch it. 那属于系统,您不应触摸它。 The best place for a DLL to reside is in the same directory as the executable that loads it. DLL驻留的最佳位置是与加载该DLL的可执行文件相同的目录。

将您的dll放在部署应用程序的文件夹中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM