MouseHook.dll in 64 bit Windows (1 Viewer)

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
I have an access database running on 32 bit Office quite happily, it uses MouseHook.dll to enable/disable the mousewheel.

I am trying to convert the database to run on both 32 bit and 64 bit Office, as some of my users are using 64 bit Office.

I have done all the usual stuff (Added PtrSafe to "Declare" statements and changed all handles to LongPtr).

I cannot get MouseHook to work on Office 64 bit however. I have it in the same folder as the database, also added it into System32 and SysWOW64 folders just in case!
Whatever I do I always get a message saying "Sorry....cannot find the MouseHook.dll file".
Some forums suggest registering the .dll with regsvr32, but this doesn't work with error message "The module "MouseHook.dll" may not be compatible with the version of Windows that you are running."

The error in Access is coming from the MouseWheel code that I have copied from the example database supplied with the download. In fact, I get the same error if I try and run the example database!

These are the changes I have done to the code to get it to run on 64 bit Access, anyone see any problems? I have tried it with various combinations of "Long" and "LongPtr":

Option Compare Database
Option Explicit

Private Declare PtrSafe Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr

Private Declare PtrSafe Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As LongPtr) As LongPtr

Private Declare PtrSafe Function StopMouseWheel Lib "MouseHook" _
(ByVal hWnd As LongPtr, ByVal AccessThreadID As LongPtr, _
Optional ByVal bNoSubformScroll As Boolean = False, Optional ByVal blIsGlobal As Boolean = False) As Boolean

Private Declare PtrSafe Function StartMouseWheel Lib "MouseHook" _
(ByVal hWnd As LongPtr) As Boolean

Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As LongPtr

' Instance returned from LoadLibrary call
Private hLib As LongPtr


Public Function MouseWheelON() As Boolean
MouseWheelON = StartMouseWheel(Application.hWndAccessApp)
If hLib <> 0 Then
hLib = FreeLibrary(hLib)
End If
End Function

Public Function MouseWheelOFF(Optional NoSubFormScroll As Boolean = False, Optional GlobalHook As Boolean = False) As Boolean
Dim s As String
Dim blRet As Boolean
Dim AccessThreadID As LongPtr

On Error Resume Next
' Our error string
s = "Sorry...cannot find the MouseHook.dll file" & vbCrLf
s = s & "Please copy the MouseHook.dll file to your Windows System folder or into the same folder as this Access MDB."

' OK Try to load the DLL assuming it is in the Window System folder
hLib = LoadLibrary("MouseHook.dll")
If hLib = 0 Then
' See if the DLL is in the same folder as this MDB
' CurrentDB works with both A97 and A2K or higher
hLib = LoadLibrary(CurrentDBDir() & "MouseHook.dll")
If hLib = 0 Then
MsgBox s, vbOKOnly, "MISSING MOUSEHOOK.dll FILE"
MouseWheelOFF = False
Exit Function
End If
End If

' Get the ID for this thread
AccessThreadID = GetCurrentThreadId()
' Call our MouseHook function in the MouseHook dll.
' Please not the Optional GlobalHook BOOLEAN parameter
' Several developers asked for the MouseHook to be able to work with
' multiple instances of Access. In order to accomodate this request I
' have modified the function to allow the caller to
' specify a thread specific(this current instance of Access only) or
' a global(all applications) MouseWheel Hook.
' Only use the GlobalHook if you will be running multiple instances of Access!
MouseWheelOFF = StopMouseWheel(Application.hWndAccessApp, AccessThreadID, NoSubFormScroll, GlobalHook)

End Function


'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:59
Joined
Sep 12, 2006
Messages
14,823
I presume the dll may not be compatible with 64 bit access.
You may not be able to assume that all of those external functions ARE ptrsafe.
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
Hi Gemma, according to the website, the .dll is the same for 32 and 64 bit.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:59
Joined
Sep 12, 2006
Messages
14,823
Curious then. Does it actually need the declarations changing?
What error do you when you use it in the updated mode?
 

sonic8

AWF VIP
Local time
Today, 11:59
Joined
Oct 27, 2015
Messages
568
according to the website, the .dll is the same for 32 and 64 bit.
According to what website?
Please clarify the source of your MouseHook.dll because the only one I know is not available for 64bit.
 

isladogs

CID VIP
Local time
Today, 10:59
Joined
Jan 14, 2017
Messages
16,088
Agree with Philipp ... I stopped using Mousehook.dll 10 years ago because it doesn't work in 64-bit.
After a quick search I found this comment in one of my apps for schools:

Rich (BB code):
'Check for 64-bit Office
#If Win64 Then '64-bit
    'MouseWheel code - not used in Win64 (64-bit Office) as MouseHook.dll doesn't work
    'Warn user of possible problems - CR v5193  17/10/2011
    If DLookup("Show64bitOffice", "Teachers", "TeacherID = '" & strLoggedOnTeacher & "'") = True Then
        DoCmd.OpenForm "frmMessageForm", , , , , , "64bitOffice"
    End If

#Else '32-bit Office - no issues
    ' Turn the MouseWheel Off
    Dim blRet As Boolean
    ' Call the MouseHook function in the MouseHook.dll.
    blRet = MouseWheelOFF(False)
#End If

These days I would use #If VBA7 but I don't believe that's relevant to the point here
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
According to what website?
Please clarify the source of your MouseHook.dll because the only one I know is not available for 64bit.
I'm starting to agree with the people who say MouseHook just doesn't work in 64 bit.

This is the site I found when I was investigating what to do.
dllyes.com/mousehook-dll/

It specifically talks about installing for 32 and 64 bit systems.
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
The next obvious question is, if MouseHook doesn't work in 64 bit Office, is there another way of disabling the Mouse Wheel?
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
Curious then. Does it actually need the declarations changing?
What error do you when you use it in the updated mode?
Hi Dave,

I get the same message no matter what I do, the database cannot find the MouseHook.dll file. Even if I just add the PtrSafe option into the declare statements and no other changes.

"Sorry....cannot find the MouseHook.dll file".
 

sonic8

AWF VIP
Local time
Today, 11:59
Joined
Oct 27, 2015
Messages
568
This is the site I found when I was investigating what to do.
dllyes.com/mousehook-dll/
The information for the DLL seems to be completely auto-generated without any clue about the actual file in question. I wouldn't be sure that the info even applies to the Mousehook.dll commonly used in Access.

This site looks highly suspicious to me. It distributes binary files without any information on the source or the purpose of the files. I wouldn't touch anything on that site with a barge pole, let alone install it on my computer.
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
The information for the DLL seems to be completely auto-generated without any clue about the actual file in question. I wouldn't be sure that the info even applies to the Mousehook.dll commonly used in Access.

This site looks highly suspicious to me. It distributes binary files without any information on the source or the purpose of the files. I wouldn't touch anything on that site with a barge pole, let alone install it on my computer.
Good advice!! Thanks.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:59
Joined
Sep 12, 2006
Messages
14,823
for what it's worth my mousehook.dll shows as 48Kb.
I haven't tried it with 64bit Access.
 

derekburleigh

New member
Local time
Today, 11:59
Joined
May 16, 2011
Messages
14
for what it's worth my mousehook.dll shows as 48Kb.
I haven't tried it with 64bit Access.
Thanks Dave,
Mine is also 48kb. There is also a 43kb version going around, I have tried that also!

I've resolved it by just removing the references to MouseHook. Reading some of the info on the Microsoft site, it looks like they have revised the actions of the mouse wheel in later versions of Access anyway, so it is not causing the problems that it used to cause in earlier versions.
 

Users who are viewing this thread

Top Bottom