+ //
+ // SETUP TYPEINFO AND ACTIVEX EVENTS
+ //
+
+ // get type info via class info
+ wxAutoIProvideClassInfo classInfo(IID_IProvideClassInfo, m_ActiveX);
+ wxASSERT(classInfo.Ok());
+
+ // type info
+ wxAutoITypeInfo typeInfo;
+ hret = classInfo->GetClassInfo(typeInfo.GetRef());
+ wxASSERT(typeInfo.Ok());
+
+ // TYPEATTR
+ TYPEATTR *ta = NULL;
+ hret = typeInfo->GetTypeAttr(&ta);
+ wxASSERT(ta);
+
+ // this should be a TKIND_COCLASS
+ wxASSERT(ta->typekind == TKIND_COCLASS);
+
+ // iterate contained interfaces
+ for (int i = 0; i < ta->cImplTypes; i++)
+ {
+ HREFTYPE rt = 0;
+
+ // get dispatch type info handle
+ hret = typeInfo->GetRefTypeOfImplType(i, &rt);
+ if (! SUCCEEDED(hret))
+ continue;
+
+ // get dispatch type info interface
+ wxAutoITypeInfo ti;
+ hret = typeInfo->GetRefTypeInfo(rt, ti.GetRef());
+ if (! ti.Ok())
+ continue;
+
+ // check if default event sink
+ bool defEventSink = false;
+ int impTypeFlags = 0;
+ typeInfo->GetImplTypeFlags(i, &impTypeFlags);
+
+ if (impTypeFlags & IMPLTYPEFLAG_FDEFAULT)
+ {
+ if (impTypeFlags & IMPLTYPEFLAG_FSOURCE)
+ {
+ // WXOLE_TRACEOUT("Default Event Sink");
+ defEventSink = true;
+ if (impTypeFlags & IMPLTYPEFLAG_FDEFAULTVTABLE)
+ {
+ // WXOLE_TRACEOUT("*ERROR* - Default Event Sink is via vTable");
+ defEventSink = false;
+ wxFAIL_MSG(wxT("Default event sink is in vtable!"));
+ }
+ }
+ }
+
+
+ // wxAutoOleInterface<> assumes a ref has already been added
+ // TYPEATTR
+ TYPEATTR *ta = NULL;
+ hret = ti->GetTypeAttr(&ta);
+ wxASSERT(ta);
+
+ if (ta->typekind == TKIND_DISPATCH)
+ {
+ // WXOLE_TRACEOUT("GUID = " << GetIIDName(ta->guid).c_str());
+ if (defEventSink)
+ {
+ wxAutoIConnectionPoint cp;
+ DWORD adviseCookie = 0;
+
+ wxAutoIConnectionPointContainer cpContainer(IID_IConnectionPointContainer, m_ActiveX);
+ wxASSERT( cpContainer.Ok());
+
+ HRESULT hret =
+ cpContainer->FindConnectionPoint(ta->guid, cp.GetRef());
+ wxASSERT ( SUCCEEDED(hret));
+
+ IDispatch* disp;
+ frame->QueryInterface(IID_IDispatch, (void**)&disp);
+ hret = cp->Advise(new wxActiveXEvents(this, ta->guid),
+ &adviseCookie);
+ wxASSERT_MSG( SUCCEEDED(hret),
+ wxString::Format(wxT("Cannot connect!\nHRESULT:%X"), (unsigned int)hret)
+ );
+ }
+ }
+
+ ti->ReleaseTypeAttr(ta);
+ }
+
+ // free
+ typeInfo->ReleaseTypeAttr(ta);
+
+ //
+ // END
+ //
+