读取vb编译生成的dll中的CLSID值与ProgID值

转自https://zhidao.baidu.com/question/488713017039798132.html

1.在vb中 引用TLBINF32.DLL类库,该文件可在c:\windows\system32下找到。

2.编写app

Private Sub Command1_Click()
 Dim TLIApp As Object
 Dim TLBInfo As TypeLibInfo 'Object
 Dim TypeInf As Object
 Set TLIApp = CreateObject("TLI.TLIApplication")
 Dim ProgID As String
 Dim CLSID As String
 ' 在这里给出dll文件名,注意它不支持长文件名
 Set TLBInfo = TLIApp.TypeLibInfoFromFile("c:\mydll.dll")
 'dll文件的guid,vb项目文件(vbp)引用的guid就是这个(TLBInfo.Guid),注册表中[TypeLib]也是这个 guid
 Debug.Print TLBInfo.Name
 Debug.Print TLBInfo.Guid 
 'dll类(CoClasses)的guid
 For Each TypeInf In TLBInfo.CoClasses
     ProgID = TypeInf.Name
     CLSID = TypeInf.Guid
     Debug.Print ProgID
     Debug.Print CLSID
 Next
 'dll接口(Interfaces)的guid
 For Each TypeInf In TLBInfo.Interfaces
    ProgID = TypeInf.Name
    CLSID = TypeInf.Guid
    Debug.Print ProgID
    Debug.Print CLSID
 Next
 '其他信息
 For Each l_types In TLBInfo.TypeInfos
    Debug.Print l_types.Name
 Next
 For Each l_constants In TLBInfo.Constants
    Debug.Print l_constants.Name
 Next
End Sub
'1.vbp例子文件
'Type=Exe
'Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\Windows\system32\stdole2.tlb#OLE Automation
'Reference=*\G{00020813-0000-0000-C000-000000000046}#1.2#0#D:\Program Files\Microsoft Office\Office12\EXCEL.EXE#Microsoft Excel 8.0 Object Library
'Reference=*\G{4AFFC9A0-5F99-101B-AF4E-00AA003F0F07}#9.0#0#D:\Program Files\Microsoft Office\Office12\MSACC.OLB#Microsoft Access 9.0 Object Library
'Reference=*\G{00025E01-0000-0000-C000-000000000046}#5.0#0#C:\Windows\system32\dao360.dll#Microsoft DAO 3.6 Object Library
'Reference=*\G{EF53050B-882E-4776-B643-EDA472E8E3F2}#2.7#0#C:\Program Files\Common Files\System\ado\msado27.tlb#Microsoft ActiveX Data Objects 2.7 Library
'Reference=*\G{4ACF03F8-3637-4DBF-B7C6-30EBAF083BB8}#1.0#0#C:\Windows\System32\mydll.dll#mydll

以上代码测试可用。

猜你喜欢

转载自blog.csdn.net/dd_zhouqian/article/details/83895400