PyObject *PyITypeLib::GetDocumentation(int pos) { BSTR name, docstring, helpfile; unsigned long helpctx; ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeLib->GetDocumentation(pos, &name, &docstring, &helpctx, &helpfile); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeLib, IID_ITypeLib); PyObject *obName = MakeOLECHARToObj(name); PyObject *obDocstring = MakeOLECHARToObj(docstring); PyObject *obHelpfile = MakeOLECHARToObj(helpfile); PyObject *ret = Py_BuildValue("(OOiO)", obName, obDocstring, helpctx, obHelpfile); SysFreeString(name); Py_XDECREF(obName); SysFreeString(docstring); Py_XDECREF(obDocstring); SysFreeString(helpfile); Py_XDECREF(obHelpfile); return ret; }
JNIEXPORT jobject JNICALL Java_org_racob_com_TypeInfo_getContainingTypeLib (JNIEnv *env, jobject obj, jint pointer) { ITypeInfo *typeInfo = (ITypeInfo *) pointer; ITypeLib* typeLib = NULL; unsigned int index = 0; HRESULT hr = typeInfo->GetContainingTypeLib(&typeLib, &index); if (!SUCCEEDED(hr)) { ThrowComFail(env, "GetContainingTypeLib failed", hr); return NULL; } int typeCount = typeLib->GetTypeInfoCount(); if (typeCount == E_NOTIMPL) { ThrowComFail(env, "GetContainingTypeLib failed to get count", hr); return NULL; } TLIBATTR *libAttr = NULL; hr = typeLib->GetLibAttr(&libAttr); if (!SUCCEEDED(hr)) { ThrowComFail(env, "Automation.loadTypeLibEx failed", hr); return NULL; } jstring guid = makeGUIDString(env, libAttr->guid); jclass autoClass = env->FindClass("org/racob/com/TypeLib"); jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(IILjava/lang/String;IIII)V"); jobject newAuto = env->NewObject(autoClass, autoCons, (jint) typeLib, index, guid, typeCount, libAttr->wLibFlags, libAttr->wMajorVerNum, libAttr->wMinorVerNum); typeLib->ReleaseTLibAttr(libAttr); return newAuto; }
// @object TLIBATTR|Type library attributes are represented as a tuple of: PyObject *PyITypeLib::GetLibAttr() { TLIBATTR *attr; ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeLib->GetLibAttr(&attr); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeLib, IID_ITypeLib); PyObject *obIID = PyWinObject_FromIID(attr->guid); PyObject *ret = NULL; if (obIID!=NULL) { ret = Py_BuildValue("Oiiiii", obIID, // @tupleitem 0|<o PyIID>|IID|The IID for the library attr->lcid, // @tupleitem 1|int|lcid|The default locale ID for the library attr->syskind, // @tupleitem 2|int|syskind|Identifies the target operating system platform attr->wMajorVerNum, // @tupleitem 3|int|majorVersion|The major version number of the library attr->wMinorVerNum, // @tupleitem 4|int|minorVersion|The minor version number of the library attr->wLibFlags); // @tupleitem 5|int|flags|Flags for the library. Py_DECREF(obIID); } { PY_INTERFACE_PRECALL; pMyTypeLib->ReleaseTLibAttr(attr); PY_INTERFACE_POSTCALL; } return ret; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CoInitialize(NULL); #if 0 // register the type lib ITypeLib* pTLib = NULL; LoadTypeLibEx(L"AnyEXETypeInfo.tlb", REGKIND_REGISTER, &pTLib); pTLib->Release(); #endif if(strstr(lpCmdLine, "/Embedding") || strstr(lpCmdLine, "-Embedding")) { ComponentClassFactory cf; DWORD regID = 0; CoRegisterClassObject(CLSID_Component, (IClassFactory*)&cf, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, ®ID); MSG ms; while(GetMessage(&ms, 0, 0, 0)) { TranslateMessage(&ms); DispatchMessage(&ms); } CoRevokeClassObject(regID); } CoUninitialize(); return 0; }
int main(int argc, char* argv[]) { // ATL helper macro to convert between ANSI and Unicode strings. USES_CONVERSION; char oneMoreTime; // ('n' or 'y') char pathToComServer[100] = {0}; do { // Get path to COM server. cout << "Please enter path to COM server (or *tlb file)"; ITypeLib* pTypeLib = NULL; cin.ignore(0, '\n'); cin.get(pathToComServer, 100); // Load type information for a COM server. if(SUCCEEDED(LoadTypeLibEx(A2W(pathToComServer), REGKIND_DEFAULT, &pTypeLib))) { // Read info about the type lib. DumpLibraryStats(pTypeLib); // Read info about COM types. DumpComTypes(pTypeLib); // COM clean up. pTypeLib->Release(); } // Want another? cout << "Do you want to enter another? (y or n)"; cin >> oneMoreTime; }while (oneMoreTime != 'n'); return 0; }
//------------------------------------------------------------------------------ // CSimpleThermostatService::InitStdDispatch // Creates the standard dispatch object that will be used when IDispatch // is requested from this object. The UPnP device object will call this // function immediately after instantiation of this object. //------------------------------------------------------------------------------ HRESULT CSimpleThermostatService::InitStdDispatch() { HRESULT hr = S_OK; ITypeLib* pTypeLib = NULL; hr = LoadRegTypeLib( LIBID_SimpleThermostatDeviceLib, 1, 0, LANG_NEUTRAL, &pTypeLib ); if( S_OK == hr ) { hr = pTypeLib->GetTypeInfoOfGuid( __uuidof(ISimpleThermostat_UPnPService), &m_pTypeInfo ); pTypeLib->Release(); } if( S_OK == hr ) { hr = CreateStdDispatch( reinterpret_cast<IUnknown*>(this), this, m_pTypeInfo, &m_pUnkStdDispatch ); } return hr; }// CSimpleThermostatService::InitStdDispatch
ITypeInfo *GetObjectTypeInfoEx(LCID lcid,REFIID iid) { HRESULT hr; ITypeInfo **ppTypeInfo; if (iid==IID_IBands) ppTypeInfo=&g_bandsTypeLib; else if (iid==IID_IChildBands) ppTypeInfo=&g_childbandsTypeLib; else return NULL; if ((*ppTypeInfo)==NULL) { //Try to load typelibrary ITypeLib *pTypeLib; ITypeInfo *pTypeInfoTmp; hr = LoadRegTypeLib(LIBID_PROJECT, 2, 0,lcid, &pTypeLib); if (FAILED(hr)) { return NULL; } hr = pTypeLib->GetTypeInfoOfGuid(iid, &pTypeInfoTmp); *ppTypeInfo=pTypeInfoTmp; pTypeLib->Release(); } if ((*ppTypeInfo)==NULL) return NULL; (*ppTypeInfo)->AddRef(); return *ppTypeInfo; }
PyObject *PyITypeLib::GetTypeInfoCount() { ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; long rc = pMyTypeLib->GetTypeInfoCount(); PY_INTERFACE_POSTCALL; return PyInt_FromLong(rc); }
CiTunesEventHandler() { m_dwRefCount=0; ITypeLib* pITypeLib = nullptr ; HRESULT hr = ::LoadRegTypeLib(LIBID_iTunesLib, 1, 5, 0x00, &pITypeLib) ; // Get type information for the interface of the object. hr = pITypeLib->GetTypeInfoOfGuid(DIID__IiTunesEvents, &m_pITypeInfo) ; pITypeLib->Release() ; }
PyObject *PyITypeLib::GetTypeInfoOfGuid(REFGUID guid) { ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; ITypeInfo *pti = NULL; PY_INTERFACE_PRECALL; HRESULT hr = pMyTypeLib->GetTypeInfoOfGuid(guid, &pti); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr, pMyTypeLib, IID_ITypeLib); return PyCom_PyObjectFromIUnknown(pti, IID_ITypeInfo); }
void tLuaCOM::getHelpInfo(char **ppHelpFile, DWORD *pHelpContext) { if(!hasTypeInfo()) { *ppHelpFile = NULL; return; } ITypeLib *typelib = NULL; BSTR helpfile; HRESULT hr = S_OK; hr = ptinfo->GetDocumentation(-1, NULL, NULL, pHelpContext, &helpfile); if(FAILED(hr) || helpfile == NULL) { *ppHelpFile = NULL; return; } // Se nao conseguiu help contextna propria interface, tenta obte-lo // na type library if(*pHelpContext == 0) { unsigned int dumb_index = 0; DWORD typelib_help_context = 0; BSTR helpfile_typelib; hr = ptinfo->GetContainingTypeLib(&typelib, &dumb_index); if(!FAILED(hr)) { hr = typelib->GetDocumentation(-1, NULL, NULL, &typelib_help_context, &helpfile_typelib); if(!FAILED(hr)) { SysFreeString(helpfile); helpfile = helpfile_typelib; *pHelpContext = typelib_help_context; } } } int str_size = SysStringLen(helpfile); *ppHelpFile = (char *) malloc((str_size + 1)*sizeof(wchar_t)); wcstombs(*ppHelpFile, helpfile, str_size+1); SysFreeString(helpfile); }
PyObject *PyITypeLib::GetTypeInfo(int pos) { ITypeInfo *pti; ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeLib->GetTypeInfo(pos, &pti); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeLib, IID_ITypeLib); return PyCom_PyObjectFromIUnknown(pti, IID_ITypeInfo); }
PyObject *PyITypeLib::GetTypeInfoType(int pos) { TYPEKIND tkind; ITypeLib *pMyTypeLib = GetI(this); if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeLib->GetTypeInfoType(pos, &tkind); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeLib, IID_ITypeLib); return PyInt_FromLong(tkind); }
PyObject *PyITypeLib::GetTypeComp() { ITypeLib *pMyTypeLib = GetI(this); ITypeComp *ptc; if (pMyTypeLib==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeLib->GetTypeComp(&ptc); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeLib, IID_ITypeLib); return PyCom_PyObjectFromIUnknown(ptc, IID_ITypeComp); }
int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low) { #ifdef _WIN32 int found = 0; TCHAR fullpath[1024]; TCHAR *p; if (!GetFullPathName(filepath.c_str(), COUNTOF(fullpath), fullpath, &p)) return 0; ITypeLib* typeLib; HRESULT hr; #ifdef _UNICODE hr = LoadTypeLib(fullpath, &typeLib); #else // If built without UNICODE, we still need to convert this string to a Unicode string. WCHAR *ole_filename = (WCHAR*) WinWStrDupFromTChar(fullpath); if (!ole_filename) return 0; hr = LoadTypeLib(ole_filename, &typeLib); free(ole_filename); #endif //~ _UNICODE if (SUCCEEDED(hr)) { TLIBATTR* typelibAttr; hr = typeLib->GetLibAttr(&typelibAttr); if (SUCCEEDED(hr)) { high = typelibAttr->wMajorVerNum; low = typelibAttr->wMinorVerNum; found = 1; } typeLib->Release(); } return found; #else return 0; #endif //~ _WIN32 }
// @pymethod |pythoncom|RegisterTypeLib|Adds information about a type library to the system registry. PyObject *pythoncom_registertypelib(PyObject *self, PyObject *args) { PyObject *obTypeLib, *obPath, *obHelpDir = Py_None; // @pyparm <o PyITypeLib>|typelib||The type library being registered. // @pyparm string|fullPath||Fully qualified path specification for the type library being registered // @pyparm string|helpDir|None|Directory in which the Help file for the library being registered can be found. Can be None. // @pyparm int|lcid|LOCALE_USER_DEFAULT|The locale ID to use. if (!PyArg_ParseTuple(args, "OO|O:RegisterTypeLib", &obTypeLib, &obPath, &obHelpDir)) return NULL; PyObject *result = NULL; BSTR bstrPath = NULL; BSTR bstrHelpDir = NULL; ITypeLib *pLib = NULL; SCODE sc; if (!PyWinObject_AsBstr(obPath, &bstrPath, FALSE)) goto done; if (!PyWinObject_AsBstr(obHelpDir, &bstrHelpDir, TRUE)) goto done; if (!PyCom_InterfaceFromPyInstanceOrObject(obTypeLib, IID_ITypeLib, (void **)&pLib, FALSE)) goto done; { // scope to avoid warning about var decl and goto. PY_INTERFACE_PRECALL; sc = RegisterTypeLib(pLib, bstrPath, bstrHelpDir); PY_INTERFACE_POSTCALL; } if (FAILED(sc)) return PyCom_BuildPyException(sc); result = Py_None; Py_INCREF(result); done: if (bstrPath) SysFreeString(bstrPath); if (bstrHelpDir) SysFreeString(bstrHelpDir); if (pLib) { PY_INTERFACE_PRECALL; pLib->Release(); PY_INTERFACE_POSTCALL; } return result; // @comm This function can be used during application initialization to register the application's type // library correctly. When RegisterTypeLib is called to register a type library, // both the minor and major version numbers are registered in hexadecimal. // <nl> In addition to filling in a complete registry entry under the type library key, // RegisterTypeLib adds entries for each of the dispinterfaces and Automation-compatible // interfaces, including dual interfaces. This information is required to create // instances of these interfaces. Coclasses are not registered (that is, // RegisterTypeLib does not write any values to the CLSID key of the coclass). }
static HRESULT maybeLoadTypeInfo() { if (!m_pTypeInfo) { ITypeLib* ptl; if (SUCCEEDED( LoadRegTypeLib( LIBID_$$Safe_root$$, 1, 0, MAKELCID(0, SORT_DEFAULT), &ptl ) )) { ptl->GetTypeInfoOfGuid( IID_IControlSurface, &m_pTypeInfo ); ptl->Release(); } else return E_NOTIMPL; } return NOERROR; }
STDAPI DllRegisterServer() { HRESULT hr = AMovieDllRegisterServer2(TRUE); // register type library WCHAR achFileName[MAX_PATH]; GetModuleFileNameW(g_hInst, achFileName, MAX_PATH); ITypeLib* pTypeLib; LoadTypeLib(achFileName, &pTypeLib); if (pTypeLib) { RegisterTypeLib(pTypeLib, achFileName, NULL); pTypeLib->Release(); } return hr; }
HRESULT ComRegistration::registerTypeLib( HMODULE hInst ) { //get the qualified path of the dll calling this function WCHAR modulePath[MAX_PATH]; GetModuleFileName( hInst, modulePath, MAX_PATH ); ITypeLib *ptlib; HRESULT hr = LoadTypeLib( modulePath, &ptlib ); if( !SUCCEEDED(hr) ) return hr; hr = RegisterTypeLib( ptlib, modulePath, NULL ); ptlib->Release(); return hr; }
HRESULT ComReg::UnRegisterTypeLibResource(const wchar_t* fullpath) { ITypeLib* pTypeLib; HRESULT hr = LoadTypeLib(fullpath, &pTypeLib); //Does not register if filename is a full path, which is what we want. if (FAILED(hr)) return hr; assert(pTypeLib); TLIBATTR* pLibAttr; hr = pTypeLib->GetLibAttr(&pLibAttr); if (FAILED(hr)) { pTypeLib->Release(); pTypeLib = 0; return hr; } assert(pLibAttr); const TLIBATTR a(*pLibAttr); pTypeLib->ReleaseTLibAttr(pLibAttr); pTypeLib->Release(); pTypeLib = 0; hr = UnRegisterTypeLib( a.guid, a.wMajorVerNum, a.wMinorVerNum, a.lcid, a.syskind); return hr; }
STDMETHODIMP CJServer::GetTypeInfo(UINT itInfo, LCID lcid, ITypeInfo **ppITypeInfo) { HRESULT hr; ITypeLib *pITypeLib; ITypeInfo **ppITI=NULL; if (0!=itInfo) return TYPE_E_ELEMENTNOTFOUND; if (NULL==ppITypeInfo) return E_POINTER; *ppITypeInfo=NULL; switch (PRIMARYLANGID(lcid)) { case LANG_NEUTRAL: case LANG_ENGLISH: ppITI=&m_pITINeutral; break; default: return DISP_E_UNKNOWNLCID; } //Load a type lib if we don't have the information already. if (NULL==*ppITI) { hr=LoadRegTypeLib(jlibid, atoi(jversion), 0, PRIMARYLANGID(lcid), &pITypeLib); if (FAILED(hr)) return hr; //Got the type lib, get type info for the interface we want hr=pITypeLib->GetTypeInfoOfGuid(jiid, ppITI); pITypeLib->Release(); if (FAILED(hr)) return hr; } // the type library is still loaded since we have an ITypeInfo from it. (*ppITI)->AddRef(); *ppITypeInfo=*ppITI; return NOERROR; }
//============================================== int g_RegisterCOM() { HRESULT hr; ITypeLib* pTypeLib; // Register typelib hr = LoadTypeLibEx(L"CP_TimeSync.exe", REGKIND_REGISTER, &pTypeLib); if( hr != S_OK) { return 1; } pTypeLib->Release(); // Register server hr = g_RegisterServer( "CP_TimeSync.exe", // application filename, full path is not needed CLSID_CP_TimeSyncClass, // ClassID GUID "CP_TimeSync", // Friendly name - shows up in dcomcnfg "CP_TimeSync.Application", // Version-independent ProgID used in late - binding "CP_TimeSync.Application.1", // ProgID with version NULL); // Threading model if( hr != S_OK) return 2; return 0; }
HRESULT ComReg::GetTypeLibAttr( const wchar_t* fullpath, TLIBATTR& a) { ITypeLib* pTypeLib; HRESULT hr = LoadTypeLib(fullpath, &pTypeLib); //Does not register if filename is a full path, which is what we want. if (FAILED(hr)) return hr; assert(pTypeLib); TLIBATTR* pLibAttr; hr = pTypeLib->GetLibAttr(&pLibAttr); if (FAILED(hr)) { pTypeLib->Release(); pTypeLib = 0; return hr; } assert(pLibAttr); a = *pLibAttr; pTypeLib->ReleaseTLibAttr(pLibAttr); pTypeLib->Release(); pTypeLib = 0; return S_OK; }
HRESULT ComReg::RegisterTypeLibResource( const wchar_t* fullpath_, const wchar_t* helpdir_) { ITypeLib* pTypeLib; HRESULT hr = LoadTypeLib(fullpath_, &pTypeLib); //Does not register if filename is a full path, which is what we want. if (FAILED(hr)) return hr; assert(pTypeLib); wchar_t* const fullpath = const_cast<wchar_t*>(fullpath_); wchar_t* const helpdir = const_cast<wchar_t*>(helpdir_); hr = RegisterTypeLib(pTypeLib, fullpath, helpdir); pTypeLib->Release(); pTypeLib = 0; return hr; }
STDAPI DllUnregisterServer() { HRESULT hr = AMovieDllRegisterServer2(FALSE); // unregister type library WCHAR achFileName[MAX_PATH]; GetModuleFileNameW(g_hInst, achFileName, MAX_PATH); ITypeLib* pTypeLib; LoadTypeLib(achFileName, &pTypeLib); if (pTypeLib) { TLIBATTR* ptla; hr = pTypeLib->GetLibAttr(&ptla); if (SUCCEEDED(hr)) { hr = UnRegisterTypeLib(ptla->guid, ptla->wMajorVerNum, ptla->wMinorVerNum, ptla->lcid, ptla->syskind); pTypeLib->ReleaseTLibAttr(ptla); } pTypeLib->Release(); } return hr; }
/* Extract IIDs and CLSIDs from qedit type library */ static void InitAllQeditTypeLibGUIDs() { ITypeLib* pQeditTypeLib = 0; HRESULT result = LoadTypeLib( kFilenameQeditTypeLib.BeginReading(), &pQeditTypeLib ); if (result == S_OK) { PRUint32 countTypeInfo = pQeditTypeLib->GetTypeInfoCount(); ITypeInfo** typeInfoPtrArray = new ITypeInfo*[countTypeInfo]; MEMBERID* memberIdArray = new MEMBERID[countTypeInfo]; InitTypeLibGUID( pQeditTypeLib, typeInfoPtrArray, memberIdArray, kNameISampleGrabber, TKIND_INTERFACE, IID_ISampleGrabber ); InitTypeLibGUID( pQeditTypeLib, typeInfoPtrArray, memberIdArray, kNameISampleGrabberCB, TKIND_INTERFACE, IID_ISampleGrabberCB ); InitTypeLibGUID( pQeditTypeLib, typeInfoPtrArray, memberIdArray, kNameClassSampleGrabber, TKIND_COCLASS, CLSID_SampleGrabber ); InitTypeLibGUID( pQeditTypeLib, typeInfoPtrArray, memberIdArray, kNameClassNullRenderer, TKIND_COCLASS, CLSID_NullRenderer ); delete[] memberIdArray; delete[] typeInfoPtrArray; } SAFE_RELEASE(pQeditTypeLib); }
bool EventSink::create() { // Retrieve the type information for the _IiTiunesEvents base // Requesting iTunes COM SDK version 1.12 VARIANT_BOOL compatible; HRESULT result = controller_->itunes_->CheckVersion(1, 12, &compatible); if (FAILED(result)) { controller_->comError("Cannot query iTunes COM SDK version"); return false; } if (!compatible) { controller_->comError("iTunes is not compatible with iTunes COM SDK version 1.12 (it is too old)"); return false; } ITypeLib *typeLib = NULL ; result = ::LoadRegTypeLib(LIBID_iTunesLib, 1, 12, 0, &typeLib); if (FAILED(result)) { controller_->comError("Could not load iTunes COM SDK version 1.12"); return false; } result = typeLib->GetTypeInfoOfGuid(DIID__IiTunesEvents, &typeInfo_) ; typeLib->Release(); if (FAILED(result)) { controller_->comError("Could not retrieve iTunes COM SDK type info"); return false; } return true; }
ITypeInfo *tCOMUtil::GetCoClassTypeInfo(IDispatch* pdisp, CLSID clsid) { CHECKPARAM(pdisp); ITypeInfo* typeinfo = NULL; ITypeLib* typelib = NULL; HRESULT hr = S_OK; { unsigned int typeinfocount = 0; hr = pdisp->GetTypeInfoCount(&typeinfocount); if(FAILED(hr) || typeinfocount == 0) return NULL; } hr = pdisp->GetTypeInfo(0, 0, &typeinfo); if(FAILED(hr)) return NULL; { unsigned int dumb_index = -1; hr = typeinfo->GetContainingTypeLib(&typelib, &dumb_index); COM_RELEASE(typeinfo); } if(FAILED(hr)) return NULL; ITypeInfo* coclasstypeinfo = tCOMUtil::GetCoClassTypeInfo(typelib, clsid); typelib->Release(); return coclasstypeinfo; }
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; } }