title: How to get the Interface ID (IID, i.e. the GUID) of an interface when importing a WinRT winmd?
body: <h1>Short version</h1>
  <p>How to you get the interface identifier (IID) for an interface from a <code>*.winmd</code> file when using <strong>IMetadataImport</strong>?</p>
  <p>e.g. <strong>Windows.Globalization.ICalendar</strong>: <code>{CA30221D-86D9-40FB-A26B-D44EB7CF08EA}</code></p>
  <h1>Longer Version</h1>
  <p>A <a href="https://blogs.msdn.microsoft.com/oldnewthing/20160622-00/?p=93725" rel="nofollow noreferrer">good example</a> is <strong>Windows.Globalization.ICalendar</strong> interface. Its IID is <code>CA30221D-86D9-40FB-A26B-D44EB7CF08EA</code>.</p>
  <h2>It's in the IDL</h2>
  <p>You can find it in the source <code>Windows.Globalization.idl</code> file:</p>
  <pre><code>[exclusiveto(Windows.Globalization.Calendar)]
  [uuid(CA30221D-86D9-40FB-A26B-D44EB7CF08EA)]
  [version(0x06020000)]
  interface ICalendar : IInspectable
  {
     //...snip...
  }
  </code></pre>
  <p><strong>Reminder</strong>: You're not supposed to parse these files. It gets compiled into a <code>*.winmd</code> assembly, and that database is the ground-truth.</p>
  <h2>It's in the header</h2>
  <p>You can find it in the <code>windows.globalization.h</code> file, which was generated from the <code>*.winmd</code> using an import tool:</p>
  <pre><code>namespace ABI {
      namespace Windows {
          namespace Globalization {
              
              MIDL_INTERFACE(&quot;CA30221D-86D9-40FB-A26B-D44EB7CF08EA&quot;)
              ICalendar : public IInspectable
              {
                 //...snip...
              }
  </code></pre>
  <h2>It's even in the winmd</h2>
  <p>You can even find the InterfaceID in the resulting compiled <code>*.winmd</code> assembly database:</p>
  <p><a href="https://i.stack.imgur.com/ohrej.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ohrej.png" alt="enter image description here" /></a></p>
  <p>But how do <strong>I</strong> get it when using the documented <code>IMetadataImporter</code> API?</p>
  <h1>Code</h1>
  <p>The <a href="https://stackoverflow.com/questions/54738573/how-to-get-an-enumeration-value-when-using-imetadataimport">abridged version</a> of how to get up and running reading <code>winmd</code> metadata files:</p>
  <pre><code>// Create your metadata dispenser:
  IMetadataDispsener dispener;
  MetaDataGetDispenser(CLSID_CorMetaDataDispenser, IMetaDataDispenser, out dispenser);
  
  //Open the winmd file we want to dump
  String filename = &quot;C:\Windows\System32\WinMetadata\Windows.Globalization.winmd&quot;;
  
  IMetaDataImport reader; //IMetadataImport2 supports generics
  dispenser.OpenScope(filename, ofRead, IMetaDataImport, out reader); //&quot;Import&quot; is used to read metadata. &quot;Emit&quot; is used to write metadata.
  </code></pre>
  <h1>Bonus Reading</h1>
  <ul>
  <li>MSDN Blogs: <a href="http://blog.monstuff.com/archives/images/Metadata_Umanaged_API.pdf" rel="nofollow noreferrer">Metadata Unmanaged API</a> <em>(a preliminary PDF version of an old Word document that, as far as i can tell, is the only Microsoft documentation for the Metadata API)</em> <em>(<a href="https://web.archive.org/web/20170312154730/http://blog.monstuff.com/archives/images/Metadata_Umanaged_API.pdf" rel="nofollow noreferrer">archive</a>)</em></li>
  </ul>