how do you write a wrapper in C#?
I'm working on a project with some groupmates, and we are using an already-established open-source C++ project for our backend... how do we get this to interface with our program if we are writing in C#? Do we need to make a C# wrapper for it? If so... how??
Thanks
-Brian
Generally speaking, the "easiest" way (though still somewhat of a pain) is to write a managed C++ CLR dll and include that as an assembly reference in your C# app. You won't be able to access any of your unmanaged types in C#, but you'll be able to use any managed C++ class automatically (as though it were a C# class). Alternatively, if you only need to export a "few" functions, you can write a normal C++ dll and explicitly import the C/C++ functions. Note that with the latter option, you're pretty much stuck with just C/C++ functions (i.e., no user-defined types). I'd recommend going with the C++ CLR dll for long-term. You can create one through Visual Studio 2005 -> New Project -> Visual C++ -> CLR -> Class Library I believe.
Once you get that going, you'll be writing manged C++ classes in your dll; those managed types can only have pointers to unmanaged code, but you can access all your unmanaged C++ code in the implementation of those managed classes.
Once you get that going, you'll be writing manged C++ classes in your dll; those managed types can only have pointers to unmanaged code, but you can access all your unmanaged C++ code in the implementation of those managed classes.
*scratches head*
Would a google search for C++/CLR explain how to make a wrapper in this fashion? (i.e. is it self explanatory, once I learn what CLR is?)
Edit: never mind - that second explanation got me on track. Thanks to both of you!
Would a google search for C++/CLR explain how to make a wrapper in this fashion? (i.e. is it self explanatory, once I learn what CLR is?)
Edit: never mind - that second explanation got me on track. Thanks to both of you!
C++/CLI is basically just the newer version of managed extensions to C++. You go about it the same as how I explained, just make sure you use their newer CLI syntax.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement