Hi,
ich verstehe den Hickhack den Du da machst eigentlich nicht. Eigentlich wollen doch alle ooP programmieren und setzen nur dann native Dll's ein, wenn es nicht anders geht, bzw. die native
Dll noch nicht in ooP übersetzt wurde (.NET).
Aus Erfahrungen mit administrativen Einschränkungen weiß ich, das sich eine Dll durchaus
selbst registrieren kann.
Jede COM-Komponente, eine VB.dll also auch, hat als exportierte Funktion: DllRegisterServer. Hier ein
VBA Proggie, das genau so eine nicht registrierte Komponente einbindet:
Hier Aufruf von DllRegisterServer einer nicht registrierten COM-Komponente:
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOLONGNAMES = &H40000
Private Const OFN_EXPLORER = &H80000
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" ( _
pOpenfilename As OPENFILENAME) As Long
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" ( _
ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32.dll" ( _
ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32.dll" ( _
ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function CallProc Lib "user32.dll" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Function ShowOpenDlg(ByVal strFilter As String, _
strTitel As String, strInitDir As String) As String
Dim lngOpenFileName As OPENFILENAME
Dim lngAnt As Long
With lngOpenFileName
.lStructSize = Len(lngOpenFileName)
.hwndOwner = 0
.hInstance = 0
If Right$(strFilter, 1) <> "|" Then _
strFilter = strFilter + "|"
For lngAnt = 1 To Len(strFilter)
If Mid$(strFilter, lngAnt, 1) = "|" Then _
Mid$(strFilter, lngAnt, 1) = Chr$(0)
Next
.lpstrFilter = strFilter
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = strInitDir
.lpstrTitle = strTitel
.flags = OFN_HIDEREADONLY Or OFN_EXPLORER Or OFN_NOCHANGEDIR
lngAnt = GetOpenFileName(lngOpenFileName)
If (lngAnt) Then
ShowOpenDlg = Trim$(.lpstrFile)
Else
ShowOpenDlg = ""
End If
End With
End Function
Private Sub Workbook_Open()
Dim hModule As Long
Dim pAdr As Long
Dim sFile As String
Application.Visible = False
sFile = ShowOpenDlg("*.DLL", "Komponente (*.dll , *.ocx) suchen", "C:\")
If sFile = "" Then Exit Sub
hModule = LoadLibrary(sFile)
If hModule = 0 Then
MsgBox "Es handelt sich um keine gültige DLL.", vbExclamation, "Fehler" & _
"aufgetreten ..."
Application.Visible = True
Exit Sub
End If
pAdr = GetProcAddress(hModule, "DllRegisterServer")
If pAdr > 0 Then
CallProc pAdr, 0, 0, 0, ByVal 0
ElseIf pAdr = 0 Then
MsgBox "Es handelt sich um keinen COM-Server", vbExclamation, "Fehler" & _
"aufgetreten ...."
End If
FreeLibrary hModule
MsgBox "Die Komponente wurde erfolgreich registriert", vbInformation, "Kein" & _
"Fehler aufgetreten."
Application.Visible = True
End Sub Eine weitere Forderung ist: Ein Objekt kann sich stets selbst aus seiner Schachtel heraus begeben und sich darstellen. Das heißt, das jedes COM-Modul über eine exportierte Funktion: DllGetClassObject verfügt und dieses via IClassFactory Dir ein Objekt aus deiner ActiveX.DLL herauszaubert - ohne registriert zu sein.
Das zweite ist über VB etwas schwierig zu realisieren - dafür habe ich aber etwas in der Hinterhand ;) |