A question: Is it possible to use PInvoke to use classes
stored in a VC++ DLL with C#? How?
If you are talking about plain old C++ classes (not COM classes or
managed classes) then no, it is not possible. This doesn't mean that the
DLL can't use classes internally, but if it was to pass a pointer out to
.NET (through an IntPtr), then it would be worthless.
If you have the .LIB and .H for this .DLL,
you could write wrappers with the Managed Extension for VC++.
If the question is:
Can I create an instance of a unmanaged C++ class and call appropriate methods exposed by this class?
The answer is you can't unless you are prepared for a change the C++ class.
1. You need to specify CallingConvention.ThisCall in the DllimportAttribute.
2. You need to specify the ordinal number as entry
3. You need to add a class factory method to your C++ dll in order to create an instance of a C++ class
4. You need to keep a list of outstanding references
5 You need to explicitly destroy the owned instance from C#
If you compare this to the creation of a managed wrapper, the latter is definitely the way to go.