www.pudn.com > VB-KAOQINXITONG.zip > modCOMDllLoader.bas
Attribute VB_Name = "modCOMDllLoader"
'***************************************************************
'
' This file depends on:
' References:
' VBoostTypes6.olb (VBoost Object Types (6.0))
' ObjCreate.olb (VBoost: Object Creation and Security)
' Files:
' FunctionDelegator.bas
' Minimal VBoost conditionals:
' None
' Conditional Compilation Values:
' FUNCTIONDELEGATOR_NOHEAP = 1 (optional)
'
'***************************************************************
Option Explicit
Private m_fInit As Boolean
Public IID_IClassFactory As IID
Public IID_IUnknown As IID
Private m_FDDllGetClassObject As FunctionDelegator 'modFunctionDelegator.mod
Private m_pCallDllGetClassObject As ICallDllGetClassObject
Private m_FDDllCanUnloadNow As FunctionDelegator
Private m_pCallDllCanUnloadNow As ICallDllCanUnloadNow
Private Sub Init()
IID_IClassFactory = IIDFromString(strIID_IClassFactory)
IID_IUnknown = IIDFromString(strIID_IUnknown)
Set m_pCallDllGetClassObject = InitDelegator(m_FDDllGetClassObject)
Set m_pCallDllCanUnloadNow = InitDelegator(m_FDDllCanUnloadNow)
m_fInit = True
End Sub
Public Function GetDllClassObject(ByVal DllPath As String, clsID As clsID, hModDll As hInstance) As IClassFactory
If Not m_fInit Then Init
If hModDll = 0 Then
hModDll = LoadLibraryEx(DllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)
If hModDll = 0 Then
Err.Raise &H80070000 + Err.LastDllError
End If
End If
m_FDDllGetClassObject.pfn = GetProcAddress(hModDll, "DllGetClassObject")
If m_FDDllGetClassObject.pfn = 0 Then
Err.Raise &H80070000 + Err.LastDllError
End If
Set GetDllClassObject = m_pCallDllGetClassObject.Call(clsID, IID_IClassFactory)
End Function
Public Sub TestUnloadDll(hModDll As hInstance)
If hModDll Then
If Not m_fInit Then Init
m_FDDllCanUnloadNow.pfn = GetProcAddress(hModDll, "DllCanUnloadNow")
If m_FDDllCanUnloadNow.pfn = 0 Then
Err.Raise &H80070000 + Err.LastDllError
End If
If m_pCallDllCanUnloadNow.Call = 0 Then
FreeLibrary hModDll
hModDll = 0
End If
End If
End Sub