I try to interact very thoroughly between the two languages. I basically have a high-performance code that I want to process in C ++ and then return the result to my application.
Everything will be compiled in Visual Studio.
I chose int as the input and output type, since sorting can be a bit winning and not quite what I'm dealing with.
C ++ I have:
#include "stdafx.h"
C # I have:
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)); } } }
So this is a pretty simple example. But I get an exception:
An unhandled exception of type "System.BadImageFormatException" occurred in Interop.exe
Additional Information: An attempt was made to download the program using the wrong format. (Exception from HRESULT: 0x8007000B)
The C ++ project is created as a console application> Dll in the create dialog. I checked the C ++ dll in the disassembler and I see Diu as an exported character.
E. What did I miss about setting up interaction?
source share