Haii
I want to check ocx that has already registered.
pls advice.
thanks.
Printable View
Haii
I want to check ocx that has already registered.
pls advice.
thanks.
Don't know, but, you can try unregistering and registering it:Now it's registered for sure (if it exists of course). You can check if it exists before those Shell() calls:Code:Shell "regsvr32 ""C:\Path\To\Lib.ocx"" /u /s"
Shell "regsvr32 ""C:\Path\To\Lib.ocx"" /s"
Anyway, i'm sure there's a better way to do it...Code:If Dir$("C:\Path\To\Lib.ocx") <> vbNullString Then
'do your thing...
End If
Hi,
I found following code from from the web. Check if it works for you.
Please comment and let others know if it works.Code:Option Explicit
Private Declare Function SetDllDirectoryA Lib "kernel32" ( _
ByVal lpPathName As String) As Long
Private Declare Function LoadLibraryA Lib "kernel32" ( _
ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" ( _
ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function CallWindowProcA Lib "user32" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" ( _
ByVal hLibModule As Long) As Long
Private Const Reg As String = "DllRegisterServer"
Private Const UnReg As String = "DllUnregisterServer"
Public Enum Register_Params
Register = 80000
unRegister = 80001
End Enum
Public Function Invokes( _
ByVal FileName As String, _
ByVal PathName As String, _
ByVal Action As Register_Params) As Boolean
Dim hModule As Long
Dim Address As Long
'// Add extra path to default search paths for component
If SetDllDirectoryA(PathName) Then
'// Get a handle to the module
hModule = LoadLibraryA(FileName)
If hModule Then
'// If the handle is valid, try to get the function address.
Select Case Action
Case Register
Address = GetProcAddress(hModule, Reg)
Case unRegister
Address = GetProcAddress(hModule, UnReg)
End Select
'// If the address is valid call the function
If Address Then
CallWindowProcA Address, 0&, ByVal 0&, ByVal 0&, ByVal 0&
FreeLibrary hModule
Invokes = True
End If
End If
End If
End Function
Private Sub Command1_Click()
If Invokes("myolecmp.ocx", "c:\", Register) Then
MsgBox "Success"
Else
MsgBox "Failed"
End If
End Sub
Cheers
Do not use the self-registration entrypoints in this way.
Both of these methods risk trashing the component's registration. Proper registration is seldom done by running regsvr32 (which just calls these entrypoints like the code above is doing). It may be safe for older components like those VB6 creates and those dating to that era (1998) but the process is actually considerably more complex than that today.
A proper installer may set many other keys and values in the registry. This approach risks wiping those out.
See the Remarks at SelfReg Table for some of the cautions.
it's work, but I just want checking that Ocx has already registered, not register or unregister the ocx. That is possible in vb?
thks.