Renuka
Renuka

Reputation: 206

Unable to load 64-bit dll Error in C#

I have 64-bit c++ ddl, which I have to use in my c# application. 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."

Iam using 64-bit OS. I tried by copying the dll into System32 folder

But still Iam getting the same error.

Please let me know the workaround for this problem........

Upvotes: 1

Views: 2297

Answers (2)

David Heffernan
David Heffernan

Reputation: 613441

I'm going to assume that your C# process is 64 bit. If it's a 32 bit process, then you cannot load a 64 bit DLL, and that's the reason for the failure.

If you copied the file into system32 then a 64 bit process will look there. If the file you copied is named sampleDll.dll, then your program will find it. 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. The most common explanation for this is that you need to install the C runtime that sampleDll.dll depends upon. Consult the documentation for this DLL to find out what its dependencies are. 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.

Finally, I would stress that you should not be copying files into the system32 directory. 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.

Upvotes: 2

Oscar
Oscar

Reputation: 13980

Place your dll in the same folder where the applications is deployed.

Upvotes: -1

Related Questions