Resgistra/Desregistra componentes
Para registrar/desregistrar DLLs/OCXs dinamicamente
- http://www.canalvisualbasic.net/foro/visual-basic-6-0/registrar-ocx-11009/
- http://www.canalvisualbasic.net/foro/sistema/registrar-comp-nentes-via-api-windows-2668/
- http://www.forosdelweb.com/625871-post4.html
- http://www.visualbasiccode.com/asp/showsn.asp?theID=2035
de...Johor Bahru, Malaysia: http://www.experts-exchange.com/M_373200.html http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20731573.html
Try this to Register a DLL programmingly:
in a module:
'Public Declare Function DllRegisterServer Lib "ComCtl32.OCX" () As Long
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Public Const ERROR_SUCCESS = &H0
Public Sub RegisterDLL(ByRef frm As Form, ByVal DLLPath As String, Optional Register As Boolean = True)
On Error GoTo ErrHandler
If Trim$(DLLPath) = "" Then Exit Sub
If Register = True Then
Dim temp As String
temp = GetSystemDir
If LCase$(DLLPath) <> LCase$(temp & "\" & dir$(DLLPath)) Then FileCopy DLLPath, temp & "\" & dir$(DLLPath)
'RegisterServer frm.hwnd, DLLPath, True
RegisterServer frm.hWnd, temp & "\" & dir$(DLLPath), True
' If Dir$(GetSystemDir & "\regsrv32.exe") = "" Then
' Shell "regsvr32 " & Dir$(DLLPath)
' Else
' Shell App.Path & "\" & "regsvr32 " & Dir$(DLLPath)
' End If
Else
'RegisterServer frm.hwnd, DLLPath, False
RegisterServer frm.hWnd, temp & "\" & dir$(DLLPath), False
' If Dir$(GetSystemDir & "\regsrv32.exe") = "" Then
' Shell "regsvr32 /u " & Dir$(DLLPath)
' Else
' Shell App.Path & "\" & "regsvr32 /u " & Dir$(DLLPath)
' End If
End If
Exit Sub
ErrHandler:
ShowErrMsg
End Sub
Public Function RegisterServer(hWnd As Long, DllServerPath As String, bRegister As Boolean)
On Error Resume Next
' going to call the DllRegisterServer/DllUnRegisterServer API of the specified library.
' there's no need to use the Regsvr32.exe anymore.
' Make sure the path is correct and that the file exists, otherwise VB will crash.
Dim LB As Long, pa As Long
LB = LoadLibrary(DllServerPath)
If bRegister Then
pa = GetProcAddress(LB, "DllRegisterServer")
Else
pa = GetProcAddress(LB, "DllUnregisterServer")
End If
If CallWindowProc(pa, hWnd, ByVal 0&, ByVal 0&, ByVal 0&) = ERROR_SUCCESS Then
'MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Successful"
Else
'MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Unsuccessful"
End If
'unmap the library's address
FreeLibrary LB
End Function
in your form, try use it like: RegisterDLL Me, myDLLFilePath, True
and you can add the para of "/u" in regsvr32 to make it execute in silent mode:
Example: regsvr32 /u mydll.dll