views:

121

answers:

1

I know I can’t compile my C# code using the default ”Platform Target : Any CPU” build setting and call a 32 bit C DLL. But if I change this setting to ”Platform Target : x86” the C# code should run under a 32-bit context and call the C DLL under that 32 bit context right? Although it doesn’t seem to work.

Do I have to register the 32-bit C DLL with some special registry or something?

I am using Windows Server 2003 64 bit.

The error is:

Runtime Error!
[Path to dll]
R6034
An application has made an attempt to load the C runtime library incorrectly.
+2  A: 

You are correct. If you're building with the platform set to x86, your 32bit DLL should work fine.

If it's not, here are some things to check:

  1. Make sure the DLL is discoverable. This usually means including it in the same folder as your application's EXE.
  2. Make sure all of the dependencies required by your DLL exist (and are discoverable) on the system. This often means installing the correct VC++ redistributable.
  3. If you're using a 32bit COM component, make sure to register the component on the system.


Edit: After seeing your comment, your issue is due to the DLL not having a proper manifest. If you embed a manifest in the DLL, it should be able to properly resolve the correct C runtime, and load it (provided the correct runtime is installed on the deployment machine.)

Reed Copsey
The C dll is from a 3rd party and I don't have the source. Is it possible to add a manifest without the source code? Thanks
CodingThunder
Yeah, use mt.exe. Otherwise, just make sure the appropriate runtimes are local, and it will typically work still.
Reed Copsey