January 12th, 2012, 10:16 am
QuoteOriginally posted by: quantericHi everyone, I am wondering if anyone can help me with interfacing... I have built a C++ DLL and am wondering how I can integrate that with C# code. There may be an additional complication in that some functions exposed in the DLL have user-defined types as inputs and outputs. I would very much appreciate your help on this.ThanksPS Could anyone recommend a good book on C# for someone who is fairly proficient in C++? Thanks.Greetings, From .Net platform point of view there are managed, unmanaged and native codes. All that works upon entire .Net platform is managed code, native code is processor instruction set and the rest is unmanaged code. So if you want to programmatically interop between C# and managed C++, you can simply use System.Reflection namespace. So if you want to programmatically interop between C# and unmanaged C++, you should use "Platform Invoke" operations, for example, after declaring unmanaged part of code you need to build a wrapper in your C# class.For example:C - code (I don't know C++ syntax ):BOOL WINAPI DllMain(/*you need to read that how to build Dll*/){//...}extern int __cdecl GetZero(){return 0;}C# - code:using System.Runtime.InteropServices;namespace WrapperCode{public static class Demo{static string yourpath; //...[DllImport(yourpath, /*calling convention = cdecl (as in unmanaged code), etc. optional parameters*/)] public static int GetZero();//...}//console entrypoint}That's all. If you want to work with non-static objects etc. you need to learn more interoperability tricks (mdsn.com).
Last edited by
Jew on January 12th, 2012, 11:00 pm, edited 1 time in total.