Automatically find TypeLibGUID
Status: Beta
Brought to you by:
jgaa
I don't know if it's easy but in this forum there is an howto to retrieve typerlibGuid from registry:
http://forums.devx.com/archive/index.php/t-68723.html
http://www.codeguru.com/forum/archive/index.php/t-177578.html
You can use the following code to get the TypeLib GUID from a file
// Copyright Albin Sunnanbo
// This code is public domain and free to use without any resitrictions, including commercial use.
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace GetComGuidLib
{
public class GetComGuid
{
[DllImport("oleaut32", CharSet = CharSet.Unicode)]
private extern static void LoadTypeLib(string dllFilePath, out ITypeLib typeLibrary);
/// <summary>
/// Returns the TypeLib Guid for the typelib in the file fileName
/// </summary>
/// <param name="fileName">The dll, ocx, tlb or other file containing a TypeLib</param>
/// <returns></returns>
public static Guid GetGuid(string fileName)
{
ITypeLib typeLibrary;
Guid guidIUnknown = Guid.Empty;
LoadTypeLib(fileName, out typeLibrary);
IntPtr pTypeLibAtt;
typeLibrary.GetLibAttr(out pTypeLibAtt);
var typeLibAtt = (System.Runtime.InteropServices.ComTypes.TYPELIBATTR)
Marshal.PtrToStructure(pTypeLibAtt, typeof(System.Runtime.InteropServices.ComTypes.TYPELIBATTR));
return typeLibAtt.guid;
}
}
}