In a my c++ dll do like this:
my dll headerfile(eg:test.h):
(1) define a callback interface class:
class CClassCallback
{
public:
virtual HRESULT OnAdded() = 0;
virtual HRESULT OnDeled() = 0;
virtual HRESULT OnFailed() = 0;
};
(2) a struct like this:
struct SAType
{
CString strTest;
int nTest;
CClassCallback* pClassCallback;
};
(3)a object interface class like:
class CTestInterface
{
public:
virtual HRESULT Test1(SAType* pTest) = 0;
virtual HRESULT Test2() = 0;
virtual void Release() = 0;
};
(4) the only export dll function:
__declspec(dllexport) CTestInterface* ConstructInterface();
my dll cppfile(eg:test.cpp):
(1) derived a class from CTestInterface
class CTestObject:public CTestInterface
{
public:
HRESULT Test1(SAtype& Test)
{
m_sType = Test;
}
HRESULT Test2()
{
}
void Release()
{
delete this;
}
private:
void InnerDemoFuc()
{
if(true)
{
m_sType.pClassCallback->OnAdded();
}
}
SAtype m_sType;
}
(2) construct a object and return its interface:
CTestInterface* ConstructInterface()
{
return new CTestObject();
}
that's ok for dll.(real code is more complex)
when I use my dll in MFC UI APP like this:
(1) derive a class from CClassCallback:
class CClassCallbackEx : public CClassCallback
{
public:
CClassCallbackEx();
virtual HRESULT OnAdded()
{
.....
}
virtual HRESULT OnDeled()
{
}
virtual HRESULT OnFailed()
{
}
}
(2) Use the dll like this:
CTestInterface* m_pInterface = ConstructInterface();
SAType sAtype;
sAtype->pClassCallback = new CClassCallbackEx();
m_pInterface->Test1(sAtype);
.......
m_pInterface->Relese();
m_pInterface=NULL;
delete (CClassCallbackEx)sAtype->pClassCallback ;
run ok.
but when i want use my dll in c# + .net UI app,some questions:
(1) i cannot get the CTestObject instance's interface's member function,
because the interface class is not export.i try to get the object's virture function table,failed.
(2) i have to derive a class from c++ interface in c# code, and use in C++dll, means ojbect callback, not funccallback (OOP)
i donot know how to do.
other words:
(1) C# use a C++Dll ojbect through virture class
(2) C++dll use a C# object through virture class
Give me some suggestions,pls