cristianbuse / VBA-UserForm-MouseScroll

Use the Mouse Scroll Wheel to scroll VBA UserForms and Controls
MIT License
70 stars 12 forks source link

DLL runtime error #20

Closed GaryFrieder closed 1 year ago

GaryFrieder commented 1 year ago

This code works great to enable the use of the mouse scroll wheel in list boxes in a userform running in a Word template - when tested on two different development PCs at my location. But the client who I'm producing this template for, is reporting that both of their testers are getting this runtime error: "453:Can't find DLL entry point GetCurrentThreadID in kernel 32".

I'm running Windows 10 Pro on one development machine, and Windows 10 Home on another. The client is running Windows 10 for Enterprise. All running 64-bit Office/Windows 365.

Thank you. Gary Frieder/Custom Office Development

cristianbuse commented 1 year ago

Hi @GaryFrieder ,

Could you please ask the testers to run Test1 and Test2 and get back to me with the results?

Sub Test1()
    #If Mac Then
        #If Win64 Then
            MsgBox "Mac x64"
        #Else
            MsgBox "Mac x32"
        #End If
    #Else
        #If Win64 Then
            MsgBox "Win x64"
        #Else
            MsgBox "Win x32"
        #End If
    #End If
End Sub

and

Option Explicit

#If Mac Then
    Public Function GetCurrentThreadId() As String
        GetCurrentThreadId = "Mac"
    End Function
#Else
    #If VBA7 Then
        Public Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
    #Else
        Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    #End If
#End If

Sub Test2()
    MsgBox GetCurrentThreadId() & vbNewLine & Application.Name & " - " & Application.Version
End Sub

Thanks!

I know you've already mentioned

All running 64-bit Office/Windows 365

but I would like to be sure.

GaryFrieder commented 1 year ago

Thanks Cristian. I have a remote meeting scheduled with the client tomorrow so will have them run it then and will report back.

GaryFrieder commented 1 year ago

Here are the results when the client runs the code tests on his company laptop. Test 1: Win x64 Test 2: 29156 Microsoft Word - 16.0

When I run Test 1 on my development laptop (running Windows Home), the result is: Win x32. My development PC runs Windows Pro but that is in a different location; I'll test run on that PC later today and post the results of that test as well.

cristianbuse commented 1 year ago

Hi @GaryFrieder ,

I was expecting them to get the same error Can't find DLL entry point GetCurrentThreadID .... However it seems that in Test2 the GetCurrentThreadID worked and returned 29156.

I would rule out the antivirus as the cause. Also the dll clearly exists and has the expected API. There must be something else causing the issue.

Just to eliminate any doubts could you please ask the client to download the Demo Workbook and see if the scrolling works. Of course they could just download the repo zip and import the modules from the src folder.

GaryFrieder commented 1 year ago

I've downloaded the demo and will send to the client. He's out of the office the next few days; will let you know as soon as we have results from testing the demo, may be next Monday.

cristianbuse commented 1 year ago

Maybe ask the client to also import the 4 modules (2 demo) in Word and test. Just to make sure there isn't something specific to Word that causes the issue.

GaryFrieder commented 1 year ago

I just met with the client and test-ran the Excel form demo, as well as the demo in a Word file I quickly put together using the modules exported from the Excel file. The vertical scroll feature doesn't work for him, when tested in either Excel or Word, but interestingly, the horizontal scrolling (Shift+Scroll) does work. Also, the zoom feature works when he tries Ctrl+Scroll. I'm hoping these are useful clues! - thanks.

GaryFrieder commented 1 year ago

Also worth mentioning that the client has third-party software called 'X-Mouse Button Control' installed on this laptop. (https://www.highrez.co.uk/downloads/xmousebuttoncontrol.htm) It appears that software also hooks into mouse functions so perhaps there's some kind of conflict? I can ask him to test with that software disabled or uninstalled. On the other hand, another tester at the client firm is having the same issue with the vertical scroll not working, and as far as I know, he doesn't have this third-party software installed.

cristianbuse commented 1 year ago

Hi @GaryFrieder ,

I cannot believe I forgot about X-Mouse Button Control (XMBC). I actually spoke with Phillip Gibbons (the owner of XMBC) back in January 2021.

When XMBC tries to send mouse messages then the next hook is specifically not called after redirecting the mouse message so to prevent scrolling both the active window and the window under the cursor. This was a very important piece of information that Phil shared about his software.

Meanwhile, I am using the hook for old ThunderFrame forms. They are so old that the their window does not process any WM_MOUSEWHEEL messages (I guess there were no mouse scroll wheels back then). So, I have to hook the mouse and watch for WM_MOUSEWHEEL messages to manually scroll the controls on the form. Now the fun part is that XMBC redirects the WM_MOUSEWHEEL messages to the window under the cursor but for VBA Forms that window does not support them. XMBC then doesn't call the next hook as it correctly presumes that the window under the cursor has been scrolled so it simply avoids scrolling the active window as well i.e. avoids double scrolling. The final result being that no window is scrolled and the VBA code doesn't also get any WM_MOUSEWHEEL messages.

The solution is to either close XMBC or untick the Make scroll wheel scroll window under cursor for the active profile(s):
image

Also, the Make scroll wheel scroll window under cursor feature is only useful for older Windows systems as starting with Windows 10 the active window under the mouse is scrolled by default by the OS itself. So, nothing is lost if the client turns it off.

GaryFrieder commented 1 year ago

Thanks - this is very interesting and surprisingly convoluted (well, maybe it's not that surprising!) A shame that Microsoft never updated these forms, given how heavily they're used to this day, but I guess that's not really surprising either.

I'll relay the suggestion about unticking that setting to my client, and we'll see what happens.

GaryFrieder commented 1 year ago

Happy to report that that settings change did the trick! I'm kind of sorry my client happened to be using the X-Mouse software, thereby causing the mysterious problems with your code running in my project, but very grateful you were able to point us to the solution - thanks again.