如何从Win32 DLL或OCX提取GUID

问题描述:

我们有一个.NET应用程序需要检查一个可能包含COM库(DLL和OCX)的文件夹。当我们遇到一个COM库时,我们需要完成的一件事是从COM DLL或OCX中提取GUID 。

We have a .NET app that needs to examine a folder that may contain COM libraries (DLL and OCX.) When we do encounter a COM library one thing we need to accomplish is to extract the GUID from the COM DLL or OCX.

有没有使用.NET而不使用第三方库的简单方法?

Is there a straightforward way to do this with .NET without using 3rd party libraries?

这应该适合你。它需要引用 c:\windows \system32\tlbinf32.dll ,但我假设这是可以的,因为它不是第三方组件。

This should work for you. It requires a reference to c:\windows\system32\tlbinf32.dll, but I'm assuming that is okay because it isn't a third party component.

Imports TLI 'from c:\windows\system32\tlbinf32.dll

Dim reglib As TLI.TLIApplication = New TLI.TLIApplicationClass()
Dim DLLPath As String = "c:\mycomponent.ocx"
MsgBox(reglib.TypeLibInfoFromFile(DLLPath).GUID.ToString())