Sign in to follow this  
BTownTKD

how do you write a wrapper in C#?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
*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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this