Results 1 to 3 of 3

Thread: Is it hard to use LoadLibrary() ?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2003
    Posts
    44

    Is it hard to use LoadLibrary() ?

    I want to register ocx by my program, not by Regsvr32.

    But i found LoadLibrary is of no effect in my program....

    What should i do?
    I love VB6

    < advertising links removed by moderator >

  2. #2
    Addicted Member
    Join Date
    Mar 2006
    Posts
    178

    Re: Is it hard to use LoadLibrary() ?

    You could use this from API-Guide

    edit: better example

    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
    If a post has been helpful, Rate it!

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Is it hard to use LoadLibrary() ?

    Quote Originally Posted by seacoldheart
    I want to register ocx by my program, not by Regsvr32.
    It sounds as if you're trying to install your program on another computer by copying files to it. Don't. Make an installation package and install it. ALL the files that need to be registered, not just your ocx, will be installed and registered. If you just copy files you'll probably be missing a few.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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