Here is some code that does the enumeration (it inserts the [Dispatch ID] - [Method name] pairs into the map, but this is easy to change).
/// /// \brief Returns a map of [DispId, Method Name] for the passed-in IDispatch object /// HRESULT COMTools::GetIDispatchMethods(_In_ IDispatch * pDisp, _Out_ std::map<long, std::wstring> & methodsMap) { HRESULT hr = S_OK; CComPtr<IDispatch> spDisp(pDisp); if(!spDisp) return E_INVALIDARG; CComPtr<ITypeInfo> spTypeInfo; hr = spDisp->GetTypeInfo(0, 0, &spTypeInfo); if(SUCCEEDED(hr) && spTypeInfo) { TYPEATTR *pTatt = nullptr; hr = spTypeInfo->GetTypeAttr(&pTatt); if(SUCCEEDED(hr) && pTatt) { FUNCDESC * fd = nullptr; for(int i = 0; i < pTatt->cFuncs; ++i) { hr = spTypeInfo->GetFuncDesc(i, &fd); if(SUCCEEDED(hr) && fd) { CComBSTR funcName; spTypeInfo->GetDocumentation(fd->memid, &funcName, nullptr, nullptr, nullptr); if(funcName.Length()>0) { methodsMap[fd->memid] = funcName; } spTypeInfo->ReleaseFuncDesc(fd); } } spTypeInfo->ReleaseTypeAttr(pTatt); } } return hr; }
Yiannis spyridakis
source share