Hi all,
I have programmed in native C++ and visual C#, but this is the first time I have tried Visual C++. I have read several articles describing C++/CLI and how it has grown from managed C++. Excited, I decided to try to write my own practice application. (Actually, my own class library in C++/CLI which I will use from a separate C# application.)
However, I have quickly become stuck on a few really basic things and I was hoping someone could help me out. (I'm more experienced than I am about to sound LOL) Here's my questions:
1. When I created the class library (VS2010, File->New Project-> Other languages->Visual C++->CLR->Class Library), I noticed a MyLibrary.h file and a MyLibrary.cpp file. Looking inside the MyLibrary.cpp file, all that was there is:
#include "stdafx.h"
#include "MLibrary.h"
That seems awfully basic. If I then go into the class view, right-click the class and add function, I notice it gets added to the .h file. So, what is the point of the .cpp file and how to use it? I obviously get why a .cpp file is important in native C++, but not so much for C++/CLI. For instance, I can't add a function prototype to the .H file and implement it in the .cpp file - it will complain of a class type redefinition.
2. What I want is basically the following use case:
C# application calls C++/CLR class library.
CLR class library calls CoCreateInstance to receive a COM interface and use it.
How can I expose a function in the library that would do this, without it being in the .h file? (Why don't I want it to be in the .h file? Well, I'd like to keep the #include it is going to need out of the .h file. I'm also just accustomed to putting code in .cpp files)
3. Finally, why does it say:
IntelliSense: 'Unavailable for C++/CLI'
I mean, what the heck? Is this seriously true? This could be a dealbreaker as I like to hit control space like a junkie - it helps me know what variables & functions I have, and see others I might not have known about.
Basically, my original problem is I found out that C# cannot call a particular Windows method (due to permissions) but native C++ could. I didn't want to have to create a native C++ library because then all the dllexport functions would have to be static, and I would have to marshal data from managed to unmanaged code, and if I had a managed C++ (C++/CLI) code library instead, then all I would have to do is add a reference to it and all of the functions would immediately be exposed. I wouldn't have to add a bunch of PInvoke lines for each function. All in all, C++/CLI started to sound attractive but the above questions have me worried (esp. about the IntelliSense, for which I fear there is no solution).
Thanks for the insight and help!!