I'm attempting a very basic interoperation between the 2 languages. I basically have some performance intensive code I wanna handle in C++ and then get the result back to my application.
All is going to be compiled in Visual Studio.
i have chosen int to be the input and output type since marshalling can be a bit wonky and not really what i'm dealing with.
C++ i have:
#include "stdafx.h" // default from vs2013, no idea what it is
_declspec(dllexport) int Diu(int p) {
return p * 2;
}
using System;
namespace Interop {
public class Program{
[System.Runtime.InteropServices.DllImport("Hardworker.dll")]
public static extern int Diu(int p);
private static void Main(string[] args) {
Console.WriteLine(Diu(2));
}
}
}
An unhandled exception of type 'System.BadImageFormatException'
occurred in Interop.exe
Additional information: An attempt was made to load a program with an
incorrect format. (Exception from HRESULT: 0x8007000B)
When you get this error: HRESULT: 0x8007000B
is caused by paltform incompatibility.
Check that that your compiler profile are set to the same platform(x86
, x64
or AnyCPU
).