patriciaxxx
Programmer
I am using DllRegisterServer Entry Point and not regsvr32.exe to register / unregister dll and ocx.
I have the following code on my Access 2003 Form.
My question and problem is that I can't seem to get the "Unsuccessful" msgbox to work. Let me further explain the code looks right to me, and if I enter the full path and name to a DLL or OCX file then it will indeed register or unregister that file and return the "Successful" msgbox. However if I enter an incorrect path or file name whilst no registration / unregistration occurs I still get the "Successful" msgbox when I should get the "Unsuccessful" msgbox.
Please if anyone can see what's wrong with my code I would be grateful.
I have the following code on my Access 2003 Form.
My question and problem is that I can't seem to get the "Unsuccessful" msgbox to work. Let me further explain the code looks right to me, and if I enter the full path and name to a DLL or OCX file then it will indeed register or unregister that file and return the "Successful" msgbox. However if I enter an incorrect path or file name whilst no registration / unregistration occurs I still get the "Successful" msgbox when I should get the "Unsuccessful" msgbox.
Please if anyone can see what's wrong with my code I would be grateful.
Code:
Option Compare Database
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.SetFocus
Text1.Text = "C:\somepath\somedllorocx.OCX"
Command1.Caption = "Register server"
Command2.Caption = "Unregister server"
End Sub
Private Sub Command1_Click()
Text1.SetFocus
Call RegisterServer(Me.hWnd, Text1.Text, True)
End Sub
Private Sub Command2_Click()
Text1.SetFocus
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
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