I want to callback C# method from "C++ COM dll", Here is the strategy I took.
Step 1:
In C++ Server.dll in idl I declared 2 class Class1 and Class2 as below.
[
object,
uuid(54120D45-09DE-4e61-AA30-858CE4C472B5),
oleautomation,
helpstring("Class1 Interface"),
pointer_default(unique)
]
interface IClass1 : IUnknown
{
[helpstring("GetCls2Ptr")] HRESULT GetClass2InterfacePtr(IClass2 * ptrCls);
[helpstring("SayHellow")] HRESULT SayHellow();
}
interface IClass2 : IUnknown
{
[helpstring("CallMe")] HRESULT CallMe();
}
In Class1.h
class Class1 :public IClass1
{
IClass2 **class2Obj;
STDMETHOD GetClass2InterfacePtr(IClass2 * ptrCls)
{
class2Obj= (&ptrCls);
return S_OK;
}
STDMETHOD SayHellow(void)
{
(*class2Obj)->CallMe();
return S_OK;
}
}
Step 2:
TlbImp c:\Server.tlb to generate Managed dll [ServerManaged.dll].
Step 3:
refer ServerManaged.dll in C
Step 4:
In C
using ServerManaged;
namespace Test1
{
public class CSClass : IClass2
{
IClass1 IClass1Obj=null;
public CSClass()
{
IClass1.GetClass2InterfacePtr(this);
IClass1.SayHellow();
}
void CallMe()
{
MessageBox.Show("Hurray I got a call!!");
}
}
Step 5:
I code is compiling fine, running fine, executing fine, No exception reported
But the problem is I can't say "Hurray I got a call!!" :(
Thanks in advance