Skip to content

Instantly share code, notes, and snippets.

@devhawk
Created June 11, 2012 22:10
Show Gist options
  • Save devhawk/2913046 to your computer and use it in GitHub Desktop.
Save devhawk/2913046 to your computer and use it in GitHub Desktop.
P/invoke for MetaDataGetDispenser
class WinRTInterop
{
public static IMetaDataDispenser GetMetadataDispenser()
{
var clsid = new Guid("{E5CB7A31-7512-11d2-89CE-0080C792E5D8}"); //CLSID_CorMetaDataDispenser
//var iid = new Guid("{31BCFCE2-DAFB-11D2-9F81-00C04F79A0A3}"); //IID_IMetaDataDispenserEx
var iid = new Guid("{809C652E-7396-11D2-9771-00A0C9B4D50C}"); //IID_IMetaDataDispenser
object ppv;
var hr = MetaDataGetDispenser(clsid, iid, out ppv);
return (IMetaDataDispenser)ppv;
}
[DllImport("RoMetadata.dll")]
static extern UInt32 MetaDataGetDispenser(
[MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object ppv);
[ComImport,
Guid("809C652E-7396-11D2-9771-00A0C9B4D50C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMetaDataDispenser
{
[PreserveSig]
void DefineScope(
[In] ref Guid rclsid,
[In] uint dwCreateFlags,
[In] ref Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppIUnk);
[PreserveSig]
void OpenScope(
[In, MarshalAs(UnmanagedType.LPWStr)] string szScope,
[In] CorOpenFlags dwOpenFlags,
[In] ref Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out object ppIUnk);
[PreserveSig]
void OpenScopeOnMemory(
[In] IntPtr pData,
[In] uint cbData,
[In] CorOpenFlags dwOpenFlags,
[In] ref Guid riid,
[Out, MarshalAs(UnmanagedType.IUnknown)] out object ppIUnk);
}
[Flags]
public enum CorOpenFlags : uint
{
ofRead = 0x00000000, // Open scope for read
ofWrite = 0x00000001, // Open scope for write.
ofReadWriteMask = 0x00000001, // Mask for read/write bit.
ofCopyMemory = 0x00000002, // Open scope with memory. Ask metadata to maintain its own copy of memory.
ofReadOnly = 0x00000010, // Open scope for read. Will be unable to QI for a IMetadataEmit* interface
ofTakeOwnership = 0x00000020, // The memory was allocated with CoTaskMemAlloc and will be freed by the metadata
// These are obsolete and are ignored.
// ofCacheImage = 0x00000004, // EE maps but does not do relocations or verify image
// ofManifestMetadata = 0x00000008, // Open scope on ngen image, return the manifest metadata instead of the IL metadata
ofNoTypeLib = 0x00000080, // Don't OpenScope on a typelib.
// Internal bits
ofReserved1 = 0x00000100, // Reserved for internal use.
ofReserved2 = 0x00000200, // Reserved for internal use.
ofReserved3 = 0x00000400, // Reserved for internal use.
ofReserved = 0xffffff40 // All the reserved bits.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment