TKSoft-Online

ActiveX-Datei (OCX, DLL) aus Access De- oder Registrieren PDF Drucken E-Mail
( 1 Vote )
MS-Access Codes - Codeschnipsel MS-Access System und PC-System
  
Montag, den 09. Juni 2008 um 04:00 Uhr

Problemstellung:

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 StringAs Long

Public Declare Function FreeLibrary _
    Lib "kernel32" ( _
    ByVal hLibModule As LongAs Long

Public Declare Function GetProcAddress _
    Lib "kernel32" ( _
    ByVal hModule As Long, _
    ByVal lpProcName As StringAs 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 LongAs Long

Public Declare Sub ExitThread Lib "kernel32" ( _
    ByVal dwExitCode As Long)

Public Declare Function WaitForSingleObject _
    Lib "kernel32" ( _
    ByVal hHandle As Long, _
    ByVal dwMilliseconds As LongAs Long

Public Declare Function GetExitCodeThread _
    Lib "kernel32" ( _
    ByVal hThread As Long, _
    lpExitCode As LongAs Long

Public Declare Function CloseHandle _
    Lib "kernel32" ( _
    ByVal hObject As LongAs Long

Public Function RegisterLibrary(sFile As String, _
    ByVal bRegister As BooleanAs 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"TrueThen
    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"FalseThen
    MsgBox "Datei wurde erfolgreich deregisriert"
Else
    MsgBox "Bei der Deregistrierung trat ein Fehler auf"
End If

 

DatumKlicks
Total2744
Do. 242
Mi. 234
Di. 223
Mo. 211
So. 204
Sa. 193
Fr. 183
Aktualisiert ( Donnerstag, den 01. Juli 2010 um 12:38 Uhr )
 

Kommentar schreiben


Sicherheitscode
Aktualisieren

Login

Latest Comments

Latest Forum Posts

Mehr »

Download Statistik

41 Kategorien
187 Dateien
173487 Downloads