I have a DLL in C++ with a funcion like the following:
LesMes.hpp
bool Sing_For_Me(CInstructment accompaniedBy, string song, string singer);
Meanwhile in my WPF app I was going to use the interop layer:
[ DllImport( "musicals.dll", EntryPoint="Sing_For_Me", CharSet=CharSet.Ansi )]
public static extern bool SingForMe(???????, string note, string singer);
How do I reference a CInstrument in the WPF code?
There seem to be lots of examples of strings being used, can you only use certain pre defined datatypes or something?
There isn’t any direct P/Invoke sort of way for C++ classes, but this is why C++\CLI was made.
You should make a C++\CLI Class project and there you can wrap
CInstrumentinto a .NET class and then use that in WPF.See this codeproject article for more info
Native C++ code just works with C++\CLI, there’s something called IJW (it just works). Also see this article for more.
You need to add a new project. Choose:
Your code would look like this: