views:

88

answers:

2

My solution has a
C# application project
C# User Controls project
C++ Mathematics project

One of the UserControls uses function from the Mathematics (C++ project). This UserControl is used in the application.

Building and starting the application works just fine. When typing the IntelliSense suggests all the contained classes and methods. The UserControl appears correctly, but on clicking a button which calls the C++ function I get a BadImageFormatException (it pops out on the end of the automatically created Main function).

The help suggests to use /fixed:no for linking, but that is already set up.

+1  A: 

Based on the information you are giving, it sounds like the managed code is trying to call into the C++ DLL as if it were managed code (and it is maybe built as unmanaged code). The information about BadImageFormatException discusses this:

An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly.

If you are building the C++ project as unmanaged code, you may need to use p/invoke to call into it.

Mark Wilkins
+1  A: 

You can get BadImageFormatException when running a 32bit dll on a 64bit system. Try setting the target to "x86" on all your projects.

Catalin DICU
Thanks, it worked. Can I build the dll as 64bit?
Lukas
If you don't reference any native 32bit dlls I suppose you can: set the target to x64.
Catalin DICU