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?
Printable View
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?
You could use this from API-Guide
edit: better example
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] 'E-Mail: [email][email protected][/email] 'We're going to call an API-function, without declaring it! ' Modified by G. Kleijer ' [email][email protected][/email] ' 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
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.Quote:
Originally Posted by seacoldheart