Rubrik: COM/OLE/Registry/DLL · Sonstiges | VB-Versionen: VB4, VB5, VB6 | 01.11.00 |
Dateien per Quellcode registrieren Ab sofort gehört die Fehlermeldung 429 - Objekterstellung durch ActiveX-Komponente nicht möglich der Vergangenheit an. | ||
Autor: Dieter Otter | Bewertung: | Views: 58.649 |
www.tools4vb.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Sie kennen das bestimmt: Wenn Sie in Ihrer Anwendung auf eine DLL- bzw. OCX-Datei zugreifen, welche nicht im System registriert wurde, erhalten Sie die Fehlermeldung: 429 Objekterstellung durch ActiveX-Komponente nicht möglich. Jetzt gibt es natürlich die Möglichkeit die betroffene Datei mit REGSVR32.EXE zu registrieren. Einfacher ist es natürlich, wenn man die Datei per Quellcode im System registrieren könnte. Mit dem nachfolgenden Code ist dies möglich!
' Hier alle benötigten API-Funktionen Private Declare Function LoadLibrary Lib "kernel32" _ Alias "LoadLibraryA" ( _ ByVal lpLibFileName As String) As Long Private Declare Function FreeLibrary Lib "kernel32" ( _ ByVal hLibModule As Long) As Long Private Declare Function GetProcAddress Lib "kernel32" ( _ ByVal hModule As Long, _ ByVal lpProcName As String) As Long Private 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 Private Declare Sub ExitThread Lib "kernel32" ( _ ByVal dwExitCode As Long) Private Declare Function WaitForSingleObject Lib "kernel32" ( _ ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) As Long Private Declare Function GetExitCodeThread Lib "kernel32" ( _ ByVal hThread As Long, _ lpExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" ( _ ByVal hObject As Long) As Long ' Die nachfolgende Funktion führt die Registrierung durch Public Function RegisterFile(ByVal sFile As String, _ Register As Boolean) As Boolean ' Der Parameter sFile enthält die zu ' registrierende Datei (inkl. Pfad) ' Register: True -> Datei soll registriert werden ' False -> Datei soll deregistriert werden Dim Result As Boolean Dim Lib As Long Dim sProc As String Dim r1 As Long Dim r2 As Long Dim Thread AS Long On Local Error GoTo RegError Result = False Lib = LoadLibrary(sFile) If Lib Then sProc = IIf(Register, "DllRegisterServer", _ "DllUnregisterServer") r1 = GetProcAddress(Lib, sProc) If r1 Then Thread = CreateThread(ByVal 0, 0, ByVal r1, _ ByVal 0, 0, r2) If Thread Then r2 = WaitForSingleObject(Thread, 10000) If r2 Then ' Fehler aufgetreten FreeLibrary Lib r2 = GetExitCodeThread(Thread, r2) ExitThread r2 Exit Function End If CloseHandle Thread ' OK Result = True End If End If FreeLibrary Lib End If RegError: RegisterFile = Result Exit Function End Function