1 1 1 1 1 1 1 1 1 1 Rating 5.00 (1 Vote)

Problemstellung:

Nur für 32Bit Office Versionen

Wie kann ich aus Access heraus eine ActiveX-Datei Registrieren bzw. Deregistrieren?

Folgenden Code in öffentliches Modul kopieren:

Public Declare Function LoadLibrary _
     Lib "kernel32" Alias "LoadLibraryA" ( _
     ByVal lpLibFileName As String) As Long
 
Public Declare Function FreeLibrary _
     Lib "kernel32" ( _
     ByVal hLibModule As Long) As Long
 
Public Declare Function GetProcAddress _
     Lib "kernel32" ( _
     ByVal hModule As Long, _
     ByVal lpProcName As String) As Long
 
Public Declare Function CreateThread Lib "kernel32" ( _
     lpThreadAttributes As Any, _
     ByVal dwStackSize As Long, _
     ByVal lpStartAddress As Long, _
     ByVal lParameter As Long, _
     ByVal dwCreationFlags As Long, _
     lpThreadID As Long) As Long
 
Public Declare Sub ExitThread Lib "kernel32" ( _
     ByVal dwExitCode As Long)
 
Public Declare Function WaitForSingleObject _
     Lib "kernel32" ( _
     ByVal hHandle As Long, _
     ByVal dwMilliseconds As Long) As Long
 
Public Declare Function GetExitCodeThread _
     Lib "kernel32" ( _
     ByVal hThread As Long, _
     lpExitCode As Long) As Long
 
Public Declare Function CloseHandle _
     Lib "kernel32" ( _
     ByVal hObject As Long) As Long
 
Public Function RegisterLibrary(sFile As String, _
     ByVal bRegister As Boolean) As Boolean
 
    Dim bolRet As Boolean
     Dim lngLib As Long
     Dim strProc As String
     Dim lngRet1 As Long
     Dim lngRet2 As Long
     Dim lngThread As Long
 
    On Local Error GoTo RegisterLibrary_Error
 
    bolRet = False
     lngLib = LoadLibrary(sFile)
 
    If lngLib > 0 Then
         strProc = IIf(bRegister, "DllRegisterServer", _
             "DllUnregisterServer")
         lngRet1 = GetProcAddress(lngLib, strProc)
         If lngRet1 > 0 Then
             lngThread = CreateThread(ByVal 0, 0, ByVal lngRet1, _
                 ByVal 0, 0, lngRet2)
             If lngThread > 0 Then
                 lngRet2 = WaitForSingleObject(lngThread, 10000)
                 If lngRet2 > 0 Then
                     Call FreeLibrary(lngLib)
                     lngRet2 = GetExitCodeThread(lngThread, lngRet2)
                     Call ExitThread(lngRet2)
                     Exit Function
                 End If
                 Call CloseHandle(lngThread)
                 bolRet = True
             End If
         End If
         Call FreeLibrary(lngLib)
     End If
 
RegisterLibrary_Error:
     RegisterLibrary = bolRet
 
End Function

Aufruf z.B. zum Registrieren:

If RegisterLibrary("C:\Windows\System32\Deine.dll", True) Then
     MsgBox "Datei wurde erfolgreich regisriert"
Else
     MsgBox "Bei der Registrierung trat ein Fehler auf"
End If

Aufruf z.B. zum Deregistrieren:

If RegisterLibrary("C:\Windows\System32\Dein.ocx", False) Then
     MsgBox "Datei wurde erfolgreich deregisriert"
Else
     MsgBox "Bei der Deregistrierung trat ein Fehler auf"
End If
 

 

Ähnliche Artikel