Created
June 12, 2012 23:12
-
-
Save devhawk/2920743 to your computer and use it in GitHub Desktop.
p/invoke and wrapper method for RoGetMetaDataFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//note, this wrapper funtion returns the metadata file name and token | |
//it immediately releases the importer pointer | |
static Tuple<string, UInt32> ResolveTypeName(string typename) | |
{ | |
string path; | |
object importer = null; | |
UInt32 token; | |
try | |
{ | |
var hr = RoGetMetaDataFile(typename, IntPtr.Zero, out path, out importer, out token); | |
//TODO: check HR for error | |
return Tuple.Create(path, token); | |
} | |
finally | |
{ | |
Marshal.ReleaseComObject(importer); | |
} | |
} | |
[DllImport("WinTypes.dll")] | |
static extern UInt32 RoGetMetaDataFile( | |
[MarshalAs(UnmanagedType.HString)] string name, | |
IntPtr metaDataDispenser, | |
[MarshalAs(UnmanagedType.HString)] out string metaDataFilePath, | |
[MarshalAs(UnmanagedType.Interface)] out object metaDataImport, | |
out UInt32 typeDefToken); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment