Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Created August 8, 2010 08:47
Show Gist options
  • Save cstrahan/513775 to your computer and use it in GitHub Desktop.
Save cstrahan/513775 to your computer and use it in GitHub Desktop.
/*
Here's an example of how to get info for a given COM type library.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using TYPELIBATTR = System.Runtime.InteropServices.ComTypes.TYPELIBATTR;
namespace Sandbox
{
class Program
{
public class InnerSink : ITypeLibImporterNotifySink
{
Assembly ITypeLibImporterNotifySink.ResolveRef(object typeLib)
{
return null;
}
void ITypeLibImporterNotifySink.ReportEvent(ImporterEventKind eventKind,
int eventCode,
string eventMsg)
{
}
}
public enum REGKIND
{
REGKIND_DEFAULT = 0,
REGKIND_REGISTER,
REGKIND_NONE
}
[DllImport("oleaut32.dll", CharSet = CharSet.Unicode)]
public static extern void LoadTypeLibEx(string strTypeLibName,
REGKIND regKind,
out ITypeLib TypeLib);
static void Main(string[] args)
{
ITypeLib typeLib;
LoadTypeLibEx("C:/Program Files (x86)/Apple Software Update/SoftwareUpdateAdmin.dll",
REGKIND.REGKIND_NONE,
out typeLib);
TYPELIBATTR tlibattr = new TYPELIBATTR();
IntPtr ppTLibAttr;
typeLib.GetLibAttr(out ppTLibAttr);
tlibattr = (TYPELIBATTR)Marshal.PtrToStructure(ppTLibAttr, typeof(TYPELIBATTR));
typeLib.ReleaseTLibAttr(ppTLibAttr);
Console.WriteLine(tlibattr.guid);
Console.WriteLine(tlibattr.lcid);
Console.WriteLine(tlibattr.syskind);
Console.WriteLine(tlibattr.wLibFlags);
Console.WriteLine(tlibattr.wMajorVerNum);
Console.WriteLine(tlibattr.wMinorVerNum);
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment