views:

533

answers:

2

Hello, I need to use one of my VB.NET projects in a C++ project. The interface between the two will be for the C++ code to instantiate and call methods on one of the .NET assembly objects.

Both compile to DLLs (and then the C++ DLL is loaded from the NTVDM as a VDD, but that's probably not relevant.)

If possible I would like to avoid using COM for this as I need to deploy without touching the registry. Also, I am using Visual Studio 2008 Express editions for both C++ and VB.NET.

Please, what is the best way to do this?

+1  A: 

If you don't want to use COM and I don't blame you, I would just create a webservice, and expose your functionality through that. Its easy to access a web service in C++ and easy to expose in VB.NET.

(Update)

Here is a link to a blog that talks about how to expose the web service without IIS

John Sonmez
Thanks that is an interesting idea, but unfortunately I can't use it in this instance as the VB.NET library has side-effects (authenticating as the current user and writing files as them) that require it to be run on the same machine as the rest of the program.
You can still run it on the same machine. Just expose it to your C++ code on that machine.
John Sonmez
Will I need to set it up in IIS to do this? That would make the deployment heavier than required. Sorry, I don't know much about webservices.
Posted a link in the answer for you.
John Sonmez
Thanks for the extra advice.
+1  A: 

Do you really need native C++ or can you use C++/CLI?

If you can do it all in C++/CLI, then you'll end up with a pure .NET application.

If you need 'native' C++, then you can create an assembly that includes managed and unmanaged C++ directly from Visual Studio (the native C++ calls C++/CLI which then calls through to your VB.NET).

And, if you'd prefer to have the whole lot in a single assembly you can follow the instructions for linking native C++ into C# applications. It should work for VB.NET too.

And I'd highly recommend "Expert C++/CLI" by Heege (1‐59059‐756‐7)

Seb Rose
Thanks, this looks promising. This is what I've done so far (in the C++ project): added the /clr option in Configuration -> General -> Common Language Runtime Support, and added a reference to the VB.NET project. Intellisense picks up on it straight away, and a short test compiled okay. Very nice!