Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- ' IUnknown interface
- ' every other interface inherits from IUnknown
- Private Type IUnknown
- QueryInterface As Long
- AddRef As Long
- Release As Long
- End Type
- ' ITypeLib interface
- ' information about a type library
- Private Type ITypeLib
- IUnk As IUnknown ' inherits from IUnknown
- GetTypeInfoCount As Long ' retrieves the number of type descriptions in the library
- GetTypeInfo As Long ' retrieves the specified type description in the library
- GetTypeInfoType As Long ' retrieves the type of a type description
- GetTypeInfoOfGuid As Long ' retrieves the type description that corresponds to the specified (GUID)
- GetLibAttr As Long ' retrieves the structure that contains the library's attributes
- GetTypeComp As Long ' retrieves a pointer to the ITypeComp for a type library
- GetDocumentation As Long ' retrieves the library's documentation string
- IsName As Long ' indicates whether a passed-in string contains the name of a type or a member described in the library
- FindName As Long ' finds occurrences of a type description in a type library
- ReleaseTLibAttr As Long ' releases the TLIBATTR originally obtained from GetLibAttr
- End Type
- Private Const S_OK = 0
- ' load a type library from a file
- Private Declare Function LoadTypeLib Lib "oleaut32" ( _
- ByVal szFile As Long, pptlib As Any) As Long
- ' copy memory from one location to the other
- Private Declare Sub CpyMem Lib "kernel32" Alias "RtlMoveMemory" ( _
- pDst As Any, pSrc As Any, ByVal dwLen As Long)
- Private Declare Function RegisterTypeLibForUser Lib "oleaut32" ( _
- pptlib As Any, ByVal szFullPath As Long, ByVal szHelpDir As Long) As Long
- ' open a type library
- Public Function RegisterTypeLib(ByVal sFile As String) As Boolean
- Dim ret As Long
- Dim pVTbl As Long
- Dim oTypeLib As Long
- Dim udtTypeLib As ITypeLib
- ret = LoadTypeLib(StrPtr(sFile), oTypeLib)
- If Not (ret = S_OK) Then
- MsgBox "Error reading TypeLib of file '" & sFile & "'", vbCritical
- Exit Function
- End If
- MsgBox "Opened TLB"
- ' get the VTable of ITypeLib
- CpyMem pVTbl, ByVal oTypeLib, 4
- CpyMem udtTypeLib, ByVal pVTbl, Len(udtTypeLib)
- MsgBox "Ref set"
- If Not (RegisterTypeLibForUser(udtTypeLib, VarPtr(sFile), VarPtr(GetDir(sFile))) = S_OK) Then
- MsgBox "Error registering TypeLib of file '" & sFile & "'", vbCritical
- Exit Function
- End If
- RegisterTypeLib = True
- End Function
- Public Function GetDir(ByVal strPath As String) As String
- GetDir = Left$(strPath, InStrRev(strPath, "\"))
- End Function
Advertisement
Add Comment
Please, Sign In to add comment