|
-
Feb 4th, 2003, 01:02 AM
#1
Thread Starter
Hyperactive Member
Register OCX
Hi ,
What is the safe way????? To register the OCX file or to copy the OCX file into system directory. My program need some ocx and dll. In my form load I want to register them but now I am confused whether I should register them using shell & regsv32 or simply copy them into system directory? Which is more safer
Please suggest me a good solution for both DLL and OCX,
Regards,
Gary
-
Feb 4th, 2003, 02:45 AM
#2
PowerPoster
If the OCx's are not going to be used by another program, it would be prudent if you ket thme in your own directory. If they are shared with your own apps, try keping them in your own shared directory under "Program Files\Shared\<YourCompanyName>\". In case it is used by various other applications too, then you can use the Windows system directory.
As for the code to register them, here you go:
VB Code:
' Add 2 Commandbuttons and a textbox to the form, and paste this code into the form
Option Explicit
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (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 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
Private Const ERROR_SUCCESS = &H0
Private Sub Form_Load()
Text1.Text = "C:\WINDOWS\SYSTEM\COMCTL32.OCX"
Command1.Caption = "Register server"
Command2.Caption = "Unregister server"
End Sub
Private Sub Command1_Click()
Call RegisterServer(Me.hWnd, Text1.Text, True)
End Sub
Private Sub Command2_Click()
Call RegisterServer(Me.hWnd, Text1.Text, False)
End Sub
Public Function RegisterServer(hWnd As Long, DllServerPath As String, bRegister As Boolean)
On Error Resume Next
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
'We're going to call an API-function, without declaring it!
' Modified by G. Kleijer
' 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
Hope this helps.
-
Feb 4th, 2003, 02:47 AM
#3
New Member
Regsvr32 is the best i think
-
Feb 4th, 2003, 03:38 AM
#4
PowerPoster
AFAIK, Regsvr32 also uses the same API calls.
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
|