Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing ActiveX controls

Status
Not open for further replies.

Zukkster

Technical User
Mar 18, 2002
61
GB
I want to use the msinet.ocx contol within my access app.

It isn't currently available to any of the users who will be using the app (i.e. it isn't in their c:\windows\system32 directory)

I found some code on the internet (see below) that copies the msinet.ocx file from a network location to the users PC and registers the file. It worked for a user with VB 6.0 installed on their PC, but it bombs for users without VB installed on their PC.

The error I get from access is

"Microsoft Access contains missing or broken links to ... msinet.ocx"

followed by

"Cannot find project or library"

Anyone know why?

Thanks

=============================================

The code to create the reference is called by

InstallOCX "I:\ApplicationFiles\", "msinet.ocx"

the functions it uses are

Option Explicit

'Win32 API Function Declarations
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

'Public
Public Function InstallOCX(SourcePath As String, FileName As String) As Long
Dim SysDir As String

SysDir = AddDirSep(GetSystemDir())

On Error GoTo InstallOCXErr

Call FileCopy(AddDirSep(SourcePath) & FileName, SysDir & FileName)

Call RegOCX(SysDir & FileName)

Exit Function

InstallOCXErr:
InstallOCX = Err.Number
End Function

Public Sub RegOCX(FullPath As String)
Dim lAddress As Long
Dim lModule As Long

On Error GoTo RegOCXErr

lModule = LoadLibrary(FullPath)
If lModule Then
lAddress = GetProcAddress(lModule, "DllRegisterServer")
If lAddress Then
Call CallPointer(lAddress)
Else
Call MsgBox("Function ""DllRegisterServer"" not found in module.", vbExclamation Or vbOKOnly, "Error while registering control")
End If
Call FreeLibrary(lModule)
Else
Call MsgBox("Module could not be loaded.", vbExclamation Or vbOKOnly, "Error while registering control")
End If

Exit Sub

RegOCXErr:
Call MsgBox("An error occured while registering the control" & vbCrLf & _
"""" & FullPath & """" & vbCrLf & _
"Error " & Err.Number & ": " & Err.Description, vbExclamation Or vbOKOnly, "Error while registering control")
End Sub

'Private
Private Function AddDirSep(Path As String) As String
AddDirSep = Path & IIf(Right$(Path, 1) = "\", "", "\")
End Function

Private Function CallPointer(ByVal lngPointer As Long) As Long
Dim Byt(11) As Byte

Byt(0) = &H58 'pop eax 'get return address
Byt(1) = &H59 'pop ecx 'kill hWnd
Byt(2) = &H59 'pop ecx 'kill Msg
Byt(3) = &H59 'pop ecx 'kill wParam
Byt(4) = &H59 'pop ecx 'kill lParam
Byt(5) = &H50 'push eax 'put return address back
Byt(6) = &HE9 'jump relative
lngPointer = lngPointer - VarPtr(Byt(11)) 'convert absolute address to relative address
Call CopyMemory(Byt(7), lngPointer, 4)
CallPointer = CallWindowProc(VarPtr(Byt(0)), 0&, 0&, 0&, 0&) 'call code in byt array
End Function

Private Function GetSystemDir() As String
Dim sTemp As String
Dim nRetVal As Long

sTemp = String(255, Chr(0))
nRetVal = GetSystemDirectory(sTemp, Len(sTemp) + 1)
GetSystemDir = Left$(sTemp, nRetVal)
End Function
 
Hmm. I've sort of worked out what is going wrong

User 1 opend DB, Function copies ocx file and creates reference

User 2 opens DB, they don't have OCX file but the reference has been created so it bombs and doesn't copy the ocx file to the c:\windows\system32
Anyone know how to copy reference files onto a users PC if they don't have them? or another work around that I haven't thought of
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top