Hugi
asked on
Connection Application-ActiveX
I tried to send an event from my Application to an ActiveX as follow, but the event newer touched my ActiveX - where can be the mistake?
void CSourceDoc::FireEventV(DIS PID dispid, BYTE* pbParams,
va_list argList)
{
COleDispatchDriver driver;
const CPtrArray* pConnections = m_xEventConnPt.GetConnecti ons();
ASSERT(pConnections != NULL);
int i;
int cConnections = pConnections->GetSize();
LPDISPATCH pDispatch;
for (i = 0; i < cConnections; i++)
{
pDispatch = (LPDISPATCH)(pConnections- >GetAt(i)) ;
ASSERT(pDispatch != NULL);
driver.AttachDispatch(pDis patch, FALSE);
TRY
driver.InvokeHelperV(dispi d, DISPATCH_METHOD, VT_EMPTY, NULL,pbParams, argList);
END_TRY
driver.DetachDispatch();
}
}
void CSourceDoc::FireEventV(DIS
va_list argList)
{
COleDispatchDriver driver;
const CPtrArray* pConnections = m_xEventConnPt.GetConnecti
ASSERT(pConnections != NULL);
int i;
int cConnections = pConnections->GetSize();
LPDISPATCH pDispatch;
for (i = 0; i < cConnections; i++)
{
pDispatch = (LPDISPATCH)(pConnections-
ASSERT(pDispatch != NULL);
driver.AttachDispatch(pDis
TRY
driver.InvokeHelperV(dispi
END_TRY
driver.DetachDispatch();
}
}
Event is fired by the control to container, not vice versa. If you want to access control's property or method from container you can quere for an interface and then call its method.
ASKER
But I need access to the same instance of the interface and when I quere for an interface I get a new instance.
I guess you're confused. When you create control with CoCreateInstance you get reference to IUnknown or ther interface you quere. OLe polymorphism states that you can quere any interface from any interface and get the same result. So you can quere the interface you are interested in and call its methods.
ASKER
This might be OK when I just need a method, but when I want to connect to an other process, it doesn't works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to call a method of custom interface of out of process server you need to implement marshaling to marshal call across process boundaries. If you call standard OLE inteface method i.e. IDispatch::Invoke, OLE already provides marshaling so you don't need to care.