title: Given a COM DLL, extract all classes CLSID and corresponding interface name
body: <p>My question is similar to <a href="https://stackoverflow.com/questions/2280247/windows-getting-clsid-for-dll">Getting CLSID for a DLL file?</a>, I think.</p>
  
  <p>I have a directory with some DLLs, each one implementing one or more COM interfaces. I would like to get:</p>
  
  <p>1) Each interface name
  2) The CLSID of the class implementing the interface</p>
  
  <p>For each DLL. It's important that everything can be done programatically (So I can't use some sort of COM browser and manually look up for that information).</p>
  
  <p>Later I will lookup the CLSID given the interface name and call some methods using IDispatch.</p>
  
  <p>One alternative seems to be scanning the registry trying to match the type, interface and class GUID and the .dll filename. But that seems to be slow and not robust.</p>
  
  <p>Does someone has a clear solution to this problem?</p>
  
  <p>EDIT:</p>
  
  <p>With the response of Ben Voigt, I came with the following code which suit my needs:</p>
  
  <pre><code>ITypeLib *typelib;
  ITypeInfo *typeinfo;
  LoadTypeLibEx(_T("c:\\mydir\\mycom1"), REGKIND_NONE, &amp;typelib);
  for (UINT i = 0;i &lt; typelib-&gt;GetTypeInfoCount();++i) {
      TYPEKIND typekind;
      typelib-&gt;GetTypeInfoType(i, &amp;typekind);
      if (typekind == TKIND_COCLASS) {
          // class!
          CComBSTR className;
          TYPEATTR *typeattr;
          typelib-&gt;GetTypeInfo(i, &amp;typeinfo);
          typeinfo-&gt;GetDocumentation(MEMBERID_NIL, &amp;className, NULL, NULL, NULL);
          typeinfo-&gt;GetTypeAttr(&amp;typeattr);
          GUID classGUID = typeattr-&gt;guid;
          for (UINT j = 0;j &lt; typeattr-&gt;cImplTypes;++j) {
              // interface!
              CComBSTR interfaceName;
              HREFTYPE hreftype;
              ITypeInfo *classtypeinfo;
              typeinfo-&gt;GetRefTypeOfImplType(j, &amp;hreftype);
              typeinfo-&gt;GetRefTypeInfo(hreftype, &amp;classtypeinfo);
              classtypeinfo-&gt;GetDocumentation(MEMBERID_NIL, &amp;interfaceName, NULL, NULL, NULL);
              // associate interfaceName with classGUID here
          }
      }
  }
  </code></pre>