如何提取一个Win32 DLL或OCX一个GUIDDLL、GUID、OCX

2023-09-03 04:20:56 作者:那一抹忧伤 !

我们有一个.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())