I’ve been reading this http://msdn.microsoft.com/en-us/magazine/cc163681.aspx and found the part about defining abstract base classes very interesting.
Is it possible to have a C++/CLI class wrapping a C++ class return a pointer to a pure virtual base class (from a function in C++) to C#? I have quite a complex solution in the making but being able to return a pointer to an abstract class directly would simplify things a lot. The interface I would want to return a pointer to is structred like so (in C++)
class CCommsBase
{
virtual DWORD Init(char* info[], int amount, int id1, int id2) =0;
virtual DWORD GetJPVals(SJPV* jpv, DWORD timeoutMS=kiDONTOVERRIDE)=0;
virtual DWORD GetNums(int amount, int* out, DWORD timeoutMS=kiDONTOVERRIDE)=0;
virtual DWORD GetJPWinVal(SJP* jp, int id, DWORD stake, DWORD timeoutMS=kiDONTOVERRIDE)=0;
virtual DWORD Confirm(bool *bConfirmedWin, int id, DWORD timeoutMS=kiDONTOVERRIDE)=0;
virtual bool Connected()=0;
virtual LPWSTR GetErrorString(int errCode)=0;
};
The default parameters would have to be replaced for overloaded functions in C# of course, but this wouldn’t be a problem. Is this even possible?
Thanks.
EDIT – should probably add, the arguments passed in as pointers are buffers that are filled with data inside of the functions.
C# can’t call virtual methods from native classes directly. What you need to do is to write a managed C++/CLI class that mirrors the functionality of the native class and holds a pointer to it. It then delegates each call to one of its method to the corresponding unmanaged method.