讀取vb編譯生成的dll中的CLSID值與ProgID值
阿新 • • 發佈:2018-11-26
轉自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
以上程式碼測試可用。