static PyObject* ITypeCompBind( ITypeComp* pTC, OLECHAR* S, unsigned short w ) { ITypeInfo* pI; DESCKIND DK; BINDPTR BP; PyObject* ret; unsigned long hashval = 0; PY_INTERFACE_PRECALL; #ifndef MS_WINCE // appears in the headers for CE, but wont link!? hashval = LHashValOfNameSys(SYS_WIN32,LOCALE_USER_DEFAULT,S); #endif SCODE sc = pTC->Bind(S, hashval,w, &pI, &DK, &BP); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc); switch(DK){ case DESCKIND_FUNCDESC: ret = PyObject_FromFUNCDESC(BP.lpfuncdesc); pI->ReleaseFuncDesc(BP.lpfuncdesc); break; case DESCKIND_VARDESC: ret = PyObject_FromVARDESC(BP.lpvardesc); pI->ReleaseVarDesc(BP.lpvardesc); break; case DESCKIND_TYPECOMP: ret = PyCom_PyObjectFromIUnknown(BP.lptcomp, IID_ITypeComp, FALSE); break; case DESCKIND_IMPLICITAPPOBJ: ITypeComp* pTC2; pI->GetTypeComp(&pTC2); ret = PyTuple_New(2); if (ret) { // NOTE: SET_ITEM consumes the refcounts. PyTuple_SET_ITEM( ret, 0, PyObject_FromVARDESC(BP.lpvardesc) ); PyTuple_SET_ITEM( ret, 1, ITypeCompBind(pTC2,S,w) ); } pTC2->Release(); pI->ReleaseVarDesc(BP.lpvardesc); break; case DESCKIND_NONE: default: Py_INCREF(Py_None); ret = Py_None; break; } if (pI) pI->Release(); if (ret == NULL) return NULL; PyObject *real_ret = PyTuple_New(2); if (real_ret==NULL) return NULL; // NOTE: SET_ITEM consumes the refcounts. PyTuple_SET_ITEM(real_ret, 0, PyInt_FromLong(DK) ); PyTuple_SET_ITEM(real_ret, 1, ret ); return real_ret; }
PyObject *PyITypeInfo::GetVarDesc(int index) { VARDESC *desc; ITypeInfo *pMyTypeInfo = GetI(this); if (pMyTypeInfo==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeInfo->GetVarDesc(index, &desc); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeInfo, IID_ITypeInfo); PyObject *ret = PyObject_FromVARDESC(desc); { PY_INTERFACE_PRECALL; pMyTypeInfo->ReleaseVarDesc(desc); PY_INTERFACE_POSTCALL; } return ret; }
JNIEXPORT jobject JNICALL Java_org_racob_com_TypeInfo_getVarDesc (JNIEnv *env, jobject obj, jint pointer, jint index) { ITypeInfo *typeInfo = (ITypeInfo *) pointer; VARDESC *varDesc = NULL; HRESULT hr = typeInfo->GetVarDesc(index, &varDesc); if (!SUCCEEDED(hr)) { ThrowComFail(env, "getVarDesc failed", hr); return NULL; } // We have a constant so let's save the variant jobject cValue = varDesc->varkind == VAR_CONST ? createVariant(env, varDesc->lpvarValue) : NULL; jclass autoClass = env->FindClass("org/racob/com/VarDesc"); jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(ILorg/racob/com/Variant;II)V"); jobject newAuto = env->NewObject(autoClass, autoCons, varDesc->memid, cValue, varDesc->varkind, varDesc->wVarFlags); typeInfo->ReleaseVarDesc(varDesc); return newAuto; }
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(); }
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; }