views:

220

answers:

3

Please suggest me the best way to use .NET dll in VC++ project.

+4  A: 

Make it ComVisible. See link text

Henrik
Is this the only approach or else there is another ?
Ashish Ashu
I don't know any other practical approach.
Henrik
+1  A: 

If you make a Managed (CLR) VC++ project (I believe you can just set this in the compiler settings, though I'm not 100% sure if you need to change anything else in code to get it to work properly), you can use the .Net code without any "com" code, though you will have to write managed c++ code (this way you can also get the advantages of both managed .Net code as well as the advantages of standard c++)

Grant Peters
Unfortunately it is not that simple. 1st you have to manage how all stuff will be communicating from managed to unmanaged area in your code (there are unmanaged pointers * and managed pointers ^ for example). Also C++/CLI doesn't support the whole C++ standard (specially in advanced areas like templates, etc).So if you really need a 'easy' way you should take COM. If you are ready for a 'hard' way (which will lead to very fast code) you can use C++/CLI
Oliver
IMHO, handling the different C++/CLI pointers is a LOT easier than doing COM interfaces and I personally haven't had any problems using templates in C++/CLI, though you probably can't have managed templates, never tried that, but you can always fall back on generics if you need to (I'm not saying they are the same, but they both have advantages/disadvantages).
Grant Peters
A: 

As an alternative, if you don't mind using the mono version instead of Microsoft, you can embed the mono runtime in your VC++ code (it's plain C) and use it to load the assembly and call methods, as described here.

axel_c