Results 1 to 4 of 4

Thread: Register OCX

  1. #1

    Thread Starter
    Hyperactive Member CHAMPGARY's Avatar
    Join Date
    Jul 2002
    Posts
    386

    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

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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:
    1. ' Add 2 Commandbuttons and a textbox to the form, and paste this code into the form
    2. Option Explicit
    3.  
    4. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    5. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    6. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    7. 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
    8. Private Const ERROR_SUCCESS = &H0
    9.  
    10. Private Sub Form_Load()
    11.     Text1.Text = "C:\WINDOWS\SYSTEM\COMCTL32.OCX"
    12.     Command1.Caption = "Register server"
    13.     Command2.Caption = "Unregister server"
    14. End Sub
    15.  
    16. Private Sub Command1_Click()
    17.     Call RegisterServer(Me.hWnd, Text1.Text, True)
    18. End Sub
    19.  
    20. Private Sub Command2_Click()
    21.     Call RegisterServer(Me.hWnd, Text1.Text, False)
    22. End Sub
    23.  
    24. Public Function RegisterServer(hWnd As Long, DllServerPath As String, bRegister As Boolean)
    25.     On Error Resume Next
    26.  
    27.     'KPD-Team 2000
    28.     'URL: [url]http://www.allapi.net/[/url]
    29.     'E-Mail: [email][email protected][/email]
    30.     'We're going to call an API-function, without declaring it!
    31.  
    32.     ' Modified by G. Kleijer
    33.     ' [email][email protected][/email]
    34.     ' going to call the DllRegisterServer/DllUnRegisterServer API of the specified library.
    35.     ' there's no need to use the Regsvr32.exe anymore.
    36.  
    37.     ' Make sure the path is correct and that the file exists, otherwise VB will crash.
    38.  
    39.     Dim lb As Long, pa As Long
    40.     lb = LoadLibrary(DllServerPath)
    41.  
    42.     If bRegister Then
    43.         pa = GetProcAddress(lb, "DllRegisterServer")
    44.     Else
    45.         pa = GetProcAddress(lb, "DllUnregisterServer")
    46.     End If
    47.  
    48.     If CallWindowProc(pa, hWnd, ByVal 0&, ByVal 0&, ByVal 0&) = ERROR_SUCCESS Then
    49.         MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Successful"
    50.    Else
    51.         MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Unsuccessful"
    52.     End If
    53.     'unmap the library's address
    54.     FreeLibrary lb
    55. End Function

    Hope this helps.

  3. #3
    New Member
    Join Date
    Jan 2003
    Location
    India
    Posts
    8
    Regsvr32 is the best i think

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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
  •  



Click Here to Expand Forum to Full Width