views:

154

answers:

2

So I am new to .net and c++ and am in need of a "library" of functions that can be called and also events that are raised in the main application that is using the library.

I have a C++ library (.lib) that I want to add another layer (wrapper) on top of it and only expose a few functions and events for the main application. I don't know which app technology to use : C#, VB.net, or CLR Winform (Dont know if that is the right name).

What am I looking to do? What should I be searching for on Google?

I imagine I should be looking to make a DLL (but what kind? I have seen C, C++, and .net C++)

Do I expose a C++ class? But how do I raise events? Virtual Functions I believe right?

Do I create some kind of object that the application references to have events/functions?

As you can see I am new to this technology and a newb in this area.

Thank you

A: 

Woah :)

..CLR Winform..

You mean C++/CLI ?

Well .. It all depends on which language you wan't to use your wrapper with. A .dll can be many different things, implementation-wise, but they all have something in common: They got data which you can use from other applications. That data being methods, classes, public integers, whatever :)

If you want to use your facade in C++, then write the .dll in C++. If you want to use it from .Net, write it in any .Net language you want, using P/Invoke, or use C++/CLI - But beware of the hundreds of pitfalls there is when doing stuff cross-language. .Net uses a garbage collector, C++ doesn't (by default :) You could ofc use something like Boost pointers or the likes to get a "GC-feeling".). You don't mention which IDE you're planning to use or which O/S you're targetting. A .dll in windows is different than one in Linux for example.

Bottom-line: It depends on your target language, O/S and for easiness of writing the facade, the IDE :)

Good luck with it.

Visual studio: C++ dll, .Net dll, native C++ to .Net wrapper using C++/CLI

cwap
Sorry this will be a windows based application developed in VS2008.I believe what I am hearing is that I could make a managed C++ DLL and use the exposed class I create to call functions and also use virtual functions as the callback/event handlers? Is that a fair statement?
Yup, that's correct.. Though I don't know why you want virtual functions, as they are only good for inheritance. Using a managed C++ dll as a facade, you can do everything you can do in other .Net languages (using System.Object-derived types, events, delegates, and all the other goodies :) ). - But beware of the memory leaks and the major differences between your .Net environment in managed C++ and the native C++ dll. You need to make sure your release your native resource manually, and create your managed resources in the .Net way, using the garbage collector.
cwap
+1  A: 

So given that you have already written a c/c++ DLL, and now want to write a GUI which uses it, here are my suggestions:

  1. Write the GUI in the .net framework, namely: managed c++, c# or VB.net (I personally prefer c#).
  2. To get the DLL functionality over to the .net app, you have a few options: use the P/Invoke, or use managed c++ wrappers.

On item #2, my personal suggestion, assuming your DLL has more than a few functions, is to write a managed c++ DLL. Here is a fairly basic, but good tutorial, it essentially comes down to compiling the DLL as managed code, and writing a wrapper class/es to allow other .net apps access to the unmanaged functions/classes.

DeusAduro