Short version
How to you get the interface identifier (IID) for an interface from a *.winmd
file when using IMetadataImport?
e.g. Windows.Globalization.ICalendar: {CA30221D-86D9-40FB-A26B-D44EB7CF08EA}
Longer Version
A good example is Windows.Globalization.ICalendar interface. Its IID is CA30221D-86D9-40FB-A26B-D44EB7CF08EA
.
It's in the IDL
You can find it in the source Windows.Globalization.idl
file:
[exclusiveto(Windows.Globalization.Calendar)]
[uuid(CA30221D-86D9-40FB-A26B-D44EB7CF08EA)]
[version(0x06020000)]
interface ICalendar : IInspectable
{
//...snip...
}
Reminder: You're not supposed to parse these files. It gets compiled into a *.winmd
assembly, and that database is the ground-truth.
It's in the header
You can find it in the windows.globalization.h
file, which was generated from the *.winmd
using an import tool:
namespace ABI {
namespace Windows {
namespace Globalization {
MIDL_INTERFACE("CA30221D-86D9-40FB-A26B-D44EB7CF08EA")
ICalendar : public IInspectable
{
//...snip...
}
It's even in the winmd
You can even find the InterfaceID in the resulting compiled *.winmd
assembly database:
But how do I get it when using the documented IMetadataImporter
API?
Code
The abridged version of how to get up and running reading winmd
metadata files:
// Create your metadata dispenser:
IMetadataDispsener dispener;
MetaDataGetDispenser(CLSID_CorMetaDataDispenser, IMetaDataDispenser, out dispenser);
//Open the winmd file we want to dump
String filename = "C:\Windows\System32\WinMetadata\Windows.Globalization.winmd";
IMetaDataImport reader; //IMetadataImport2 supports generics
dispenser.OpenScope(filename, ofRead, IMetaDataImport, out reader); //"Import" is used to read metadata. "Emit" is used to write metadata.
Bonus Reading
- MSDN Blogs: Metadata Unmanaged API (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) (archive)