HRESULT CJSProxyObj::SetEventNames() { ITypeInfo* pInfo; if (m_pTypeInfo == nullptr) pInfo = theApp.m_pEventTypeInfo.p; else pInfo = m_pTypeInfo.p; TYPEATTR *pta = nullptr;; HRESULT hr = pInfo->GetTypeAttr(&pta); if (FAILED(hr)) return hr; BSTR bstrName = ::SysAllocString(L""); FUNCDESC *pfd = nullptr; unsigned int uiNames = 0; for (int i = 0; i < pta->cFuncs; i++) { hr = pInfo->GetFuncDesc(i, &pfd); if (FAILED(hr)) continue; hr = pInfo->GetNames(pfd->memid, &bstrName, 1, &uiNames); if (SUCCEEDED(hr) && bstrName && SysStringLen(bstrName)) { m_mapDispId.Add(pfd->memid, bstrName); ATLTRACE(_T("*********Add function '%s' in Tangram*******\r\n"), OLE2T(bstrName)); } pInfo->ReleaseFuncDesc(pfd); pfd = nullptr; } pInfo->ReleaseTypeAttr(pta); return hr; }
/* Extract GUID with name nameGUID and assign it to guid */ static void InitTypeLibGUID( ITypeLib* const pTypeLib, ITypeInfo** const typeInfoPtrArray, MEMBERID* const memberIdArray, const nsAString& nameGUID, const TYPEKIND typeKindGUID, GUID& guid) { // Copy nameGUID as FindName requires a non const string nsString copyNameGUID(nameGUID); PRInt32 hashValue = 0; PRUint16 countFound = 1; HRESULT result = pTypeLib->FindName( copyNameGUID.BeginWriting(), hashValue, typeInfoPtrArray, memberIdArray, &countFound ); if (result == S_OK) { for (PRUint16 i = 0; i < countFound; ++i) { ITypeInfo* pTypeInfo = typeInfoPtrArray[i]; typeInfoPtrArray[i] = 0; TYPEATTR* pTypeAttribute = 0; result = pTypeInfo->GetTypeAttr(&pTypeAttribute); if (result == S_OK) { if (pTypeAttribute->typekind == typeKindGUID) { guid = pTypeAttribute->guid; } pTypeInfo->ReleaseTypeAttr(pTypeAttribute); } SAFE_RELEASE(pTypeInfo); } } }
static PyObject *PyRecord_reduce(PyObject *self, PyObject *args) { PyObject *ret = NULL; PyRecord *pyrec = (PyRecord *)self; PyObject *obModule = NULL, *obModDict = NULL, *obFunc = NULL; ITypeInfo *pti = NULL; TYPEATTR *pta = NULL; ULONG cb; HRESULT hr; GUID structguid; if (!PyArg_ParseTuple(args, ":reduce")) return NULL; hr = pyrec->pri->GetTypeInfo(&pti); if (FAILED(hr)||pti==NULL) { PyCom_BuildPyException(hr); goto done; } hr = pti->GetTypeAttr(&pta); if (FAILED(hr)||pta==NULL) { PyCom_BuildPyException(hr); goto done; } hr = pyrec->pri->GetGuid(&structguid); if (FAILED(hr)) { PyCom_BuildPyException(hr); goto done; } hr = pyrec->pri->GetSize(&cb); if (FAILED(hr)) { PyCom_BuildPyException(hr); goto done; } obModule = PyImport_ImportModule("pythoncom"); if (obModule) obModDict = PyModule_GetDict(obModule); // no ref added! if (obModDict) obFunc = PyDict_GetItemString(obModDict, "GetRecordFromGuids"); // no ref added! if (!obFunc) { PyErr_Clear(); PyErr_SetString(PyExc_RuntimeError, "pythoncom.GetRecordFromGuids() can't be located!"); goto done; } ret = Py_BuildValue("O(NHHiNN)", obFunc, PyWinObject_FromIID(pta->guid), pta->wMajorVerNum, pta->wMinorVerNum, pta->lcid, PyWinObject_FromIID(structguid), PyString_FromStringAndSize((char *)pyrec->pdata, cb)); done: if (pta&& pti) pti->ReleaseTypeAttr(pta); if (pti) pti->Release(); Py_XDECREF(obModule); // obModDict and obFunc have no new reference. return ret; }
PyObject *PyITypeInfo::GetTypeAttr() { TYPEATTR *attr; ITypeInfo *pMyTypeInfo = GetI(this); if (pMyTypeInfo==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeInfo->GetTypeAttr(&attr); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeInfo, IID_ITypeInfo); /* PyObject *obIID = PyWinObject_FromIID(attr->guid); PyObject *obDescAlias; // Some (only a few 16 bit MSOffice only one so far, and even then only occasionally!) // servers seem to send invalid tdescAlias when its not actually an alias. if (attr->typekind == TKIND_ALIAS) obDescAlias = MakeTypeDesc(&attr->tdescAlias); else { Py_INCREF(Py_None); obDescAlias=Py_None; } PyObject *obIDLDesc = MakeIDLDesc(&attr->idldescType); PyObject *ret = Py_BuildValue("(OiiiiiiiiiiiiiOO)", obIID, // @tupleitem 0|<o PyIID>|IID|The IID attr->lcid, // @tupleitem 1|int|lcid|The lcid attr->memidConstructor, // @tupleitem 2|int|memidConstructor|ID of constructor attr->memidDestructor, // @tupleitem 3|int|memidDestructor|ID of destructor, attr->cbSizeInstance, // @tupleitem 4|int|cbSizeInstance|The size of an instance of this type attr->typekind, // @tupleitem 5|int|typekind|The kind of type this information describes. One of the win32con.TKIND_* constants. attr->cFuncs, // @tupleitem 6|int|cFuncs|Number of functions. attr->cVars, // @tupleitem 7|int|cVars|Number of variables/data members. attr->cImplTypes, // @tupleitem 8|int|cImplTypes|Number of implemented interfaces. attr->cbSizeVft, // @tupleitem 9|int|cbSizeVft|The size of this type's VTBL attr->cbAlignment, // @tupleitem 10|int|cbAlignment|Byte alignment for an instance of this type. attr->wTypeFlags, // @tupleitem 11|int|wTypeFlags|One of the pythoncom TYPEFLAG_ attr->wMajorVerNum, // @tupleitem 12|int|wMajorVerNum|Major version number. attr->wMinorVerNum, // @tupleitem 13|int|wMinorVerNum|Minor version number. obDescAlias, // @tupleitem 14|<o TYPEDESC>|obDescAlias|If TypeKind == pythoncom.TKIND_ALIAS, specifies the type for which this type is an alias. obIDLDesc // @tupleitem 15|<o IDLDESC>|obIDLDesc|IDL attributes of the described type. ); Py_XDECREF(obDescAlias); Py_XDECREF(obIDLDesc); Py_XDECREF(obIID); ***/ PyObject *ret = PyObject_FromTYPEATTR(attr); { PY_INTERFACE_PRECALL; pMyTypeInfo->ReleaseTypeAttr(attr); PY_INTERFACE_POSTCALL; } return ret; }
void _AfxUnregisterInterfaces(ITypeLib* pTypeLib) { TCHAR szKey[128]; lstrcpy(szKey, _T("Interface\\")); LPTSTR pszGuid = szKey + lstrlen(szKey); int cTypeInfo = pTypeLib->GetTypeInfoCount(); for (int i = 0; i < cTypeInfo; i++) { TYPEKIND tk; if (SUCCEEDED(pTypeLib->GetTypeInfoType(i, &tk)) && (tk == TKIND_DISPATCH || tk == TKIND_INTERFACE)) { ITypeInfo* pTypeInfo = NULL; if (SUCCEEDED(pTypeLib->GetTypeInfo(i, &pTypeInfo))) { TYPEATTR* pTypeAttr; if (SUCCEEDED(pTypeInfo->GetTypeAttr(&pTypeAttr))) { #if defined(_UNICODE) || defined(OLE2ANSI) StringFromGUID2(pTypeAttr->guid, pszGuid, GUID_CCH); #else WCHAR wszGuid[39]; StringFromGUID2(pTypeAttr->guid, wszGuid, GUID_CCH); _wcstombsz(pszGuid, wszGuid, GUID_CCH); #endif _AfxRecursiveRegDeleteKey(HKEY_CLASSES_ROOT, szKey); pTypeInfo->ReleaseTypeAttr(pTypeAttr); } pTypeInfo->Release(); } } } }
CLSID tCOMUtil::FindCLSID(ITypeInfo* interface_typeinfo) { ITypeLib* ptypelib = NULL; ITypeInfo* ptypeinfo = NULL; long count = 0; IID iid = IID_NULL; TYPEATTR* ptypeattr = NULL; TYPEKIND tkind; bool found = false; CLSID clsid = IID_NULL; // gets IID interface_typeinfo->GetTypeAttr(&ptypeattr); iid = ptypeattr->guid; interface_typeinfo->ReleaseTypeAttr(ptypeattr); ptypeattr = NULL; // Gets type library interface_typeinfo->GetContainingTypeLib(&ptypelib, NULL); // iterates looking for IID inside some coclass count = ptypelib->GetTypeInfoCount(); while(count-- && !found) { ptypelib->GetTypeInfoType(count, &tkind); if(tkind != TKIND_COCLASS) continue; // look inside ptypelib->GetTypeInfo(count, &ptypeinfo); // gets counts and clsid ptypeinfo->GetTypeAttr(&ptypeattr); long ifaces_count = ptypeattr->cImplTypes; clsid = ptypeattr->guid; ptypeinfo->ReleaseTypeAttr(ptypeattr); ptypeattr = NULL; TYPEFLAGS typeflags; HREFTYPE RefType; ITypeInfo* piface_typeinfo = NULL; while(ifaces_count-- && !found) { ptypeinfo->GetRefTypeOfImplType(ifaces_count, &RefType); ptypeinfo->GetRefTypeInfo(RefType, &piface_typeinfo); piface_typeinfo->GetTypeAttr(&ptypeattr); if(IsEqualIID(ptypeattr->guid, iid)) { found = true; } piface_typeinfo->ReleaseTypeAttr(ptypeattr); ptypeattr = NULL; COM_RELEASE(piface_typeinfo); } COM_RELEASE(ptypeinfo); } COM_RELEASE(ptypelib); return clsid; }
ITypeInfo *tCOMUtil::GetDispatchTypeInfo(IDispatch* pdisp) { ITypeInfo* typeinfo = NULL; HRESULT hr = pdisp->GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT, &typeinfo); if(FAILED(hr)) return NULL; TYPEATTR *ptypeattr = NULL; typeinfo->GetTypeAttr(&ptypeattr); TYPEKIND typekind = ptypeattr->typekind; if(typekind == TKIND_DISPATCH) { typeinfo->ReleaseTypeAttr(ptypeattr); return typeinfo; } // tries to find another description of the same // interface in the typelib with TKIND_DISPATCH ITypeLib *ptypelib = NULL; unsigned int dumb = 0; IID iid = ptypeattr->guid; hr = typeinfo->GetContainingTypeLib(&ptypelib, &dumb); typeinfo->ReleaseTypeAttr(ptypeattr); // if there's no containing type lib, we have to // trust this one is the right type info if(FAILED(hr)) return typeinfo; // obtem a typeinfo do iid fornecido // caso haja uma implementacao dispinterface, // esta' e' que sera' retornada (segundo // documentacao do ActiveX ITypeInfo* typeinfo_guid = NULL; hr = ptypelib->GetTypeInfoOfGuid(iid, &typeinfo_guid); if(FAILED(hr)) { ptypelib->Release(); return typeinfo; } // verifica se e' dispinterface TYPEATTR *ptypeattr_iface = NULL; hr = typeinfo_guid->GetTypeAttr(&ptypeattr_iface); TYPEKIND typekind_iface = ptypeattr_iface->typekind; typeinfo_guid->ReleaseTypeAttr(ptypeattr_iface); if(typekind_iface == TKIND_DISPATCH) { // releases original type information COM_RELEASE(typeinfo); return typeinfo_guid; } else { COM_RELEASE(typeinfo_guid); // returns original type info return typeinfo; } }
ITypeInfo *tCOMUtil::GetDefaultInterfaceTypeInfo(ITypeInfo* pCoClassinfo, bool source) { ITypeInfo* typeinfo = NULL; //Use this to determine success TYPEATTR* pTA = NULL; HRESULT hr = S_OK; if (SUCCEEDED(pCoClassinfo->GetTypeAttr(&pTA))) { UINT i = 0; int iFlags = 0; for (i=0; i < pTA->cImplTypes; i++) { //Get the implementation type for this interface hr = pCoClassinfo->GetImplTypeFlags(i, &iFlags); if (FAILED(hr)) continue; if (iFlags & IMPLTYPEFLAG_FDEFAULT || pTA->cImplTypes == 1) { if(source == false && !(iFlags & IMPLTYPEFLAG_FSOURCE) || source == true && (iFlags & IMPLTYPEFLAG_FSOURCE)) { HREFTYPE hRefType=NULL; /* * This is the interface we want. Get a handle to * the type description from which we can then get * the ITypeInfo. */ pCoClassinfo->GetRefTypeOfImplType(i, &hRefType); hr = pCoClassinfo->GetRefTypeInfo(hRefType, &typeinfo); // gets typeattr info TYPEATTR *ptypeattr = NULL; GUID guid; TYPEKIND typekind; hr = typeinfo->GetTypeAttr(&ptypeattr); if(FAILED(hr)) { typeinfo->Release(); typeinfo = NULL; break; } guid = ptypeattr->guid; typekind = ptypeattr->typekind; typeinfo->ReleaseTypeAttr(ptypeattr); if(typekind == TKIND_DISPATCH) { // found! break; } } } } pCoClassinfo->ReleaseTypeAttr(pTA); } return typeinfo; }
BOOL CTreeItem::ExpandTypeInfo( HTREEITEM hitem ) { ASSERT(m_pTree) ; ASSERT(hitem) ; CTreeItem* pNewItem = NULL ; HRESULT hr = S_OK ; TV_INSERTSTRUCT tvis ; CString strError = "Enumerating TypeInfo" ; TYPEATTR* pattr = NULL ; ITypeInfo* pti = GetTypeInfo() ; ASSERT(pti) ; BOOL fExpand = FALSE ; tvis.hParent = hitem ; tvis.hInsertAfter = TVI_LAST ; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN ; tvis.item.iImage = typeUnknown ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; TRY { ENSURE(pti); hr = pti->GetTypeAttr(&pattr) ; if FAILED(hr) { strError.Format(_T("ITypeInfo::GetTypeAttr() failed"), hr ) ; AfxThrowMemoryException() ; } switch(pattr->typekind) { // typedef [attributes] enum [tag] { // enumlist // } enumname; // // "typedef enum enumname" case TKIND_ENUM: fExpand = ExpandVars( hitem ) ; break ; // typedef [attributes] // struct [tag] { // memberlist // } structname; // // "typedef struct structname" case TKIND_RECORD: fExpand = ExpandVars( hitem ) ; break ; // [attributes] // module modulename { // elementlist // }; case TKIND_MODULE: if (pattr->cVars) { // Add "Constants" folder // #pragma warning (suppress: 6211) #pragma warning (suppress: 6014) pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeProperties ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Constants") ; tvis.item.iImage = typeConstants ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cFuncs) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeMethods ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cFuncs ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Functions") ; tvis.item.iImage = typeMethods ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // interface interfacename [:baseinterface] { // functionlist // }; case TKIND_INTERFACE: fExpand = ExpandFuncs( hitem) ; if (pattr->cImplTypes) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeImplTypes ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.pszText = _T("Inherited Interfaces") ; tvis.item.iImage = typeInterface ; tvis.item.cChildren = pattr->cImplTypes ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // dispinterface intfname { // interface interfacename // }; case TKIND_DISPATCH : if (pattr->cVars) { // Add "Constants" folder // pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeConstants ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Constants") ; tvis.item.iImage = typeConstants ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; // Add "Properties" folder // pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeProperties ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cVars ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Properties") ; tvis.item.iImage = typeProperties ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cFuncs) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeMethods ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.cChildren = pattr->cFuncs ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.pszText = _T("Methods") ; tvis.item.iImage = typeMethods ; tvis.item.iSelectedImage = tvis.item.iImage + 1 ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } if (pattr->cImplTypes) { pNewItem = new CTreeItem(m_pTree) ; pNewItem->m_Type = typeImplTypes ; pNewItem->SetTypeInfo(pti) ; pti->AddRef() ; tvis.item.pszText = _T("Inherited Interfaces") ; tvis.item.iImage = typeInterface ; tvis.item.cChildren = pattr->cImplTypes ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; m_pTree->InsertItem( &tvis ) ; fExpand = TRUE ; } break ; // [attributes] // coclass classname { // [attributes2] [interface | dispinterface] interfacename; // ... // }; case TKIND_COCLASS: fExpand = ExpandImplTypes( hitem ) ; break ; // typedef [attributes] basetype aliasname; case TKIND_ALIAS: if (pattr->tdescAlias.vt == VT_USERDEFINED) { ITypeInfo* ptiRefType = NULL ; #pragma warning (suppress: 6246) HRESULT hr = pti->GetRefTypeInfo( pattr->tdescAlias.hreftype, &ptiRefType ) ; if (FAILED(hr)) AfxThrowOleException( hr ) ; pNewItem = new CTreeItem(m_pTree) ; pNewItem->SetTypeInfo( ptiRefType ) ; pNewItem->m_Type = TypeKindToItemType( pNewItem->GetTypeKind() ) ; tvis.item.iImage = TypeKindToItemType( pNewItem->GetTypeKind() ) ; tvis.item.cChildren = 1 ; tvis.item.lParam = (LPARAM)pNewItem ; tvis.item.iSelectedImage = tvis.item.iImage ; CString sName; pNewItem->GetName(sName, TRUE ); tvis.item.pszText = sName.GetBuffer(0) ; m_pTree->InsertItem( &tvis ) ; sName.ReleaseBuffer(); fExpand = TRUE ; } break ; // typedef [attributes] union [tag] { // memberlist // } unionname; case TKIND_UNION: fExpand = ExpandVars( hitem ) ; break ; default: break ; } if (pattr) pti->ReleaseTypeAttr( pattr ) ; } CATCH(CException, pException) { ErrorMessage( strError, hr ) ; if (pNewItem) delete pNewItem ; if (pattr) pti->ReleaseTypeAttr( pattr ) ; return FALSE ; }
void DumpComTypes(ITypeLib* pTypeLib) { // Dump out the types. USES_CONVERSION; pTypeLib->AddRef(); ULONG typeCount = pTypeLib->GetTypeInfoCount(); cout << "\n****** The COM Types ******" << endl; cout << "There are " << typeCount << " in this type lib" << endl << endl; for(ULONG typeIndex = 0; typeIndex < typeCount; typeIndex++) { ITypeInfo* pInfo = NULL; TYPEATTR* typeAtt; CComBSTR temp; ULONG index = 0; ULONG numbMembers = 0; pTypeLib->GetTypeInfo(typeIndex, &pInfo); pInfo->GetTypeAttr(&typeAtt); // Based on the kind of COM type, print out some information. switch(typeAtt->typekind) { case TKIND_COCLASS: // type is a coclass. cout << "(" << typeIndex << ")" << " Coclass with " << typeAtt->cImplTypes << " interface(s). ******" << endl; temp = typeAtt->guid; cout << "->CLSID: " << W2A(temp.Copy()) << endl; pInfo->GetDocumentation(-1, &temp, NULL, NULL, NULL); cout << "->Name: " << W2A(temp.Copy()) << endl; break; case TKIND_DISPATCH: // type is a IDispatch derived interface. cout << "(" << typeIndex << ")" << " IDispatch based interface with " << typeAtt->cFuncs << " method(s). ******" << endl; temp = typeAtt->guid; cout << "->IID: " << W2A(temp.Copy()) << endl; pInfo->GetDocumentation(-1, &temp, NULL, NULL, NULL); cout << "->Name: " << W2A(temp.Copy()) << endl; numbMembers = typeAtt->cFuncs; for(index = 0; index < numbMembers; index++) { FUNCDESC* fx; pInfo->GetFuncDesc(index, &fx); pInfo->GetDocumentation(fx->memid, &temp, NULL, NULL, NULL); cout << " ->" << W2A(temp.Copy()) << " has " << fx->cParams << " params" << endl; pInfo->ReleaseFuncDesc(fx); } break; case TKIND_INTERFACE: // Type is an IUnknown derived interface. cout << "(" << typeIndex << ")" << " IUnknown based interface with " << typeAtt->cFuncs << " method(s). ******" << endl; temp = typeAtt->guid; cout << "->IID: " << W2A(temp.Copy()) << endl; pInfo->GetDocumentation(-1, &temp, NULL, NULL, NULL); cout << "->Name: " << W2A(temp.Copy()) << endl; numbMembers = typeAtt->cFuncs; for(index = 0; index < numbMembers; index++) { FUNCDESC* fx; pInfo->GetFuncDesc(index, &fx); pInfo->GetDocumentation(fx->memid, &temp, NULL, NULL, NULL); cout << " ->" << W2A(temp.Copy()) << " has " << fx->cParams << " param(s)" << endl; pInfo->ReleaseFuncDesc(fx); } break; case TKIND_ENUM: // Type is an enum. cout << "(" << typeIndex << ")" << " Enum with " << typeAtt->cVars << " member(s). ******" << endl; pInfo->GetDocumentation(-1, &temp, NULL, NULL, NULL); cout << "->Name: " << W2A(temp.Copy()) << endl; numbMembers = typeAtt->cVars; for(index = 0; index < numbMembers; index++) { VARDESC* var; pInfo->GetVarDesc(index, &var); pInfo->GetDocumentation(var->memid, &temp, NULL, NULL, NULL); cout << " ->" << W2A(temp.Copy()) << endl; pInfo->ReleaseVarDesc(var); } break; default: cout << "Some other type I don't care about..." << endl; } cout << endl; pInfo->ReleaseTypeAttr(typeAtt); pInfo->Release(); } pTypeLib->Release(); }
ITypeInfo *tCOMUtil::GetDefaultInterfaceTypeInfo(ITypeInfo* pCoClassinfo, bool source) { ITypeInfo* typeinfo = NULL; // if the component does not have a dispinterface typeinfo // for events, we stay with an interface typeinfo ITypeInfo* interface_typeinfo = NULL; TYPEATTR* pTA = NULL; HRESULT hr = S_OK; if (SUCCEEDED(pCoClassinfo->GetTypeAttr(&pTA))) { UINT i = 0; int iFlags = 0; for (i=0; i < pTA->cImplTypes; i++) { //Get the implementation type for this interface hr = pCoClassinfo->GetImplTypeFlags(i, &iFlags); if (FAILED(hr)) continue; if (iFlags & IMPLTYPEFLAG_FDEFAULT || pTA->cImplTypes == 1) { if(source == false && !(iFlags & IMPLTYPEFLAG_FSOURCE) || source == true && (iFlags & IMPLTYPEFLAG_FSOURCE)) { HREFTYPE hRefType=0; /* * This is the interface we want. Get a handle to * the type description from which we can then get * the ITypeInfo. */ pCoClassinfo->GetRefTypeOfImplType(i, &hRefType); hr = pCoClassinfo->GetRefTypeInfo(hRefType, &typeinfo); // gets typeattr info TYPEATTR *ptypeattr = NULL; GUID guid; TYPEKIND typekind; hr = typeinfo->GetTypeAttr(&ptypeattr); if(FAILED(hr)) { COM_RELEASE(typeinfo); break; } guid = ptypeattr->guid; typekind = ptypeattr->typekind; typeinfo->ReleaseTypeAttr(ptypeattr); if(typekind == TKIND_DISPATCH) { // found! COM_RELEASE(interface_typeinfo); break; } else // hold this pointer. If we do not find // anything better, we stay with this typeinfo { COM_RELEASE(interface_typeinfo); interface_typeinfo = typeinfo; typeinfo = NULL; } } } } pCoClassinfo->ReleaseTypeAttr(pTA); } if(!typeinfo) return interface_typeinfo; else return typeinfo; }
BOOL comauto::RecordInfo::IsMatchingType( IRecordInfo *pRecordInfo) { BOOL rt = TRUE; ITypeInfo* otypeinfo = 0; ITypeInfo* rectypeinfo = 0; ITypeInfo* orectypeinfo = 0; TYPEATTR* otypeattr = 0; VARDESC* vd = 0; VARDESC* ovd = 0; BSTR varname = NULL; BSTR ovarname = NULL; try { WRAP( pRecordInfo->GetTypeInfo( &otypeinfo)) WRAP( otypeinfo->GetTypeAttr( &otypeattr)) if (m_typeattr->guid == otypeattr->guid) goto Cleanup; if (m_typeattr->cVars != otypeattr->cVars) {rt=FALSE; goto Cleanup;} unsigned short ii; for (ii = 0; ii < m_typeattr->cVars; ++ii) { if (vd) { m_typeinfo->ReleaseVarDesc( vd); vd = NULL; } WRAP( m_typeinfo->GetVarDesc( ii, &vd)) if (ovd) { otypeinfo->ReleaseVarDesc( ovd); ovd = NULL; } WRAP( otypeinfo->GetVarDesc( ii, &ovd)) if (vd->elemdescVar.tdesc.vt != ovd->elemdescVar.tdesc.vt || vd->oInst != ovd->oInst) { rt=FALSE; goto Cleanup; } UINT nn; if (varname) { ::SysFreeString( varname); varname = NULL; } WRAP( m_typeinfo->GetNames( vd->memid, &varname, 1, &nn)) if (ovarname) { ::SysFreeString( ovarname); ovarname = NULL; } WRAP( otypeinfo->GetNames( ovd->memid, &ovarname, 1, &nn)) if (wcscmp( varname, ovarname) != 0) { rt=FALSE; goto Cleanup; } if (vd->elemdescVar.tdesc.vt == VT_USERDEFINED) { if (rectypeinfo) { rectypeinfo->Release(); rectypeinfo = 0; } WRAP( m_typeinfo->GetRefTypeInfo( vd->elemdescVar.tdesc.hreftype, &rectypeinfo)) if (orectypeinfo) { orectypeinfo->Release(); orectypeinfo = NULL; } WRAP( m_typeinfo->GetRefTypeInfo( ovd->elemdescVar.tdesc.hreftype, &orectypeinfo)) comauto::RecordInfo rec( rectypeinfo); comauto::RecordInfo orec( orectypeinfo); if (rec.IsMatchingType( &orec) == FALSE) { rt=FALSE; goto Cleanup; } } } } catch (...) { rt = FALSE; } Cleanup: if (vd) m_typeinfo->ReleaseVarDesc( vd); if (ovd) otypeinfo->ReleaseVarDesc( ovd); if (otypeattr) otypeinfo->ReleaseTypeAttr( otypeattr); if (rectypeinfo) rectypeinfo->Release(); if (orectypeinfo) orectypeinfo->Release(); if (otypeinfo) otypeinfo->Release(); if (varname) ::SysFreeString( varname); if (ovarname) ::SysFreeString( ovarname); return rt; }
STDMETHODIMP ESource::InitEvent(IDispatch *SourceDispatch, OrxScript *ORexxScript, FILE *LogFile) { ITypeInfo *SourceType; TYPEATTR *TypeAttributes; BSTR SourceName; unsigned int NameCount; int i; FUNCDESC *FuncDesc; char DispIDName[29]; PEMAP NewMap; HRESULT RetCode=S_OK; int EMCount; FPRINTF2(LogFile,"created a new Event Source. %p\n",this); FPRINTF2(DLLlogfile,"created a new Event Source.%p\n",this); EventType = AddScriptlet; Source = SourceDispatch; // Mimick the ParseProcedures "THIS" parameter by returning this pointer. Engine = ORexxScript; Connected = false; ConnectionPoint = NULL; Container = NULL; logfile = LogFile; RetCode = GetTypeInfo(&SourceType); if (SUCCEEDED(RetCode)) { RetCode = SourceType->GetTypeAttr(&TypeAttributes); memcpy(&SourceGUID,&TypeAttributes->guid,sizeof(GUID)); EMCount = TypeAttributes->cFuncs; SourceType->ReleaseTypeAttr(TypeAttributes); OLECHAR lGUID[50]; StringFromGUID2(SourceGUID,lGUID,sizeof(lGUID)); FPRINTF2(logfile,"The GUID is %S and there are %d functions.\n",lGUID,EMCount); /* For each entry in the type library, create an entry on the Event Map chain. * This is a many to one relation. Each of the different Source Disp ID's * will translate to the same Sink Disp ID. There is only one chunk of code * being bound to this Event that the Type Library is describing. So every * Source call must map to the same Sink. */ for (i=0; i<EMCount; i++) { SourceType->GetFuncDesc(i, &FuncDesc); // Despite what the documentation says, this returns Max Names, not Max Names - 1. // The first name is the function name, the remainder if they exist are parameters. SourceType->GetNames(FuncDesc->memid, &SourceName, 1, &NameCount); sprintf(DispIDName,"%d",FuncDesc->memid); // This creates the entry for the function with an invalid DispID to call. RetCode = AddMap(DispIDName,&NewMap); if (FAILED(RetCode)) return RetCode; FPRINTF2(logfile,"ESource::InitEvent - AddScriptlet \"%S\" \n",SourceName); NewMap->SourceEventName = SourceName; SourceType->ReleaseFuncDesc(FuncDesc); } SourceType->Release(); } else { FPRINTF2(logfile,"Could not obtain TypInfo for this event! HRESULT %08x\n",RetCode); } return RetCode; }