|
-
Feb 19th, 2001, 07:25 AM
#1
Thread Starter
Junior Member
Hi!!
Can I register or un-register a OCX control at runtime?
I mean for example if I use an especific OCX control how can i register ir while I have got a splash screen ? Can I do that? and can I un-register the OCX while the program is finishing with an splash screen too?
I need an example please and THANKS!!
-
Feb 19th, 2001, 08:57 AM
#2
regsvr32 /u C:\Path\Filename.ocx
un-registers a dll or ocx file.
regsvr32 C:\Path\Filename.ocx
registers the file.
-
Feb 19th, 2001, 08:59 AM
#3
you can do this at any time. There is also a silent option to do this behind the scenes, but you don't get the warning message if the register / un-register fails.
This is :
regsvr32 /u /s C:\Path\Filename.ocx
-
Feb 20th, 2001, 06:08 AM
#4
Here's an alternative that doesn't require regsvr32 to be on the machine and in the system path.
I didn't write it, although I have made some mods. Who wroteit, well, that has been lost in the mists of time. My apologies to those concerned.
Code:
Public Enum RegUnreg
Register = 0
UnRegister = 1
End Enum
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 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 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 Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'The actual codey bit.
Public Function RegisterDLLOROCX(File As String, _
Optional Process As RegUnreg = Register, _
Optional PromptOnError As Boolean = False) As Boolean
Dim LoadedLib As Long
Dim EntryPoint As Long
Dim ExitCode As Long
Dim newThread As Long
Dim newThreadID As Long
On Error Resume Next
'// Check file exists
If Dir(File, vbNormal) = "" Then
If PromptOnError Then MsgBox "The file " & File & " doesn't exist", vbCritical, "DLL/OCX Register"
RegisterDLLOROCX = False
Exit Function
End If
LoadedLib = LoadLibrary(File) '// Load file
If LoadedLib = 0 Then
If PromptOnError Then MsgBox "An error occured while loading the file " & File, vbCritical, "DLL/OCX Register"
RegisterDLLOROCX = False
Exit Function
End If
'// Find right entery point
If Process = Register Then
EntryPoint = GetProcAddress(LoadedLib, "DllRegisterServer")
ElseIf Process = UnRegister Then
EntryPoint = GetProcAddress(LoadedLib, "DllUnregisterServer")
Else
If PromptOnError Then MsgBox "An error occured while loading the file " & File, vbCritical, "DLL/OCX Register"
RegisterDLLOROCX = False
Exit Function
End If
If EntryPoint = vbNull Then
If PromptOnError Then MsgBox "An error occured while locating the entery point for the file : " & vbNewLine & File, vbCritical, "DLL/OCX Register"
FreeLibrary (LoadedLib) '// Unload libarary
RegisterDLLOROCX = False
Exit Function
End If
Screen.Mousepointer = vbHourglass
newThread = CreateThread(ByVal 0, 0, ByVal EntryPoint, ByVal 0, 0, newThreadID) '// Create a new thread.
If newThread = 0 Then
Screen.Mousepointer = vbDefault
If PromptOnError Then
MsgBox "An error occured while attempting to create a new thread.", vbCritical, "DLL/OCX Register"
End If
FreeLibrary (LoadedLib) '// Unload libarary
Exit Function
End If
If WaitForSingleObject(newThread, 10000) <> 0 Then
Screen.Mousepointer = vbDefault
If PromptOnError Then MsgBox "An error occured while attempting to register/unregister the file : " & vbNewLine & File, vbCritical, "DLL/OCX Register"
ExitCode = GetExitCodeThread(newThread, ExitCode)
ExitThread (ExitCode)
FreeLibrary (LoadedLib)
RegisterDLLOROCX = False
Exit Function
End If
CloseHandle (newThread) '// Close thread
FreeLibrary (LoadedLib) '// Unload libarary
Screen.Mousepointer = vbDefault '// Reset cursor
RegisterDLLOROCX = True
End Function
Hope that helps
- gaffa
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|