2

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?

2 Answers2

1

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
John Sonmez
  • 7,128
  • 5
  • 37
  • 56
  • 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. –  Dec 23 '08 at 16:06
  • You can still run it on the same machine. Just expose it to your C++ code on that machine. – John Sonmez Dec 23 '08 at 16:07
  • 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. –  Dec 23 '08 at 16:15
  • Posted a link in the answer for you. – John Sonmez Dec 23 '08 at 16:17
1

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
  • 3,628
  • 18
  • 29
  • 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! –  Dec 23 '08 at 16:43
  • I've just followed the steps in your comment, but the C++ compiler can't see the VB class - how do I #include it? – Sideshow Bob Jun 21 '12 at 15:06