none
Compile Error Type MisMatch RRS feed

  • Question

  • Hi

    I would like to inform that the following code is taken from this Forum

    I am using MSOffice 2013 64-bit

    The Error indicated as Marked Bold which is given below

    '1. In the module level:

    Private Type POINTAPI
         X As Long
         Y As Long
    End Type

    Private Type MOUSEHOOKSTRUCT
         pt As POINTAPI
         hwnd As Long
         wHitTestCode As Long
         dwExtraInfo As Long
    End Type

    Private Declare PtrSafe Function FindWindow Lib "user32" _
                         Alias "FindWindowA" ( _
                                 ByVal lpClassName As String, _
                                 ByVal lpWindowName As String) As Long

    Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" _
                         Alias "GetWindowLongA" ( _
                                 ByVal hwnd As Long, _
                                 ByVal nIndex As Long) As Long

    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" _
                         Alias "SetWindowsHookExA" ( _
                                 ByVal idHook As Long, _
                                 ByVal lpfn As Long, _
                                 ByVal hmod As Long, _
                                 ByVal dwThreadId As Long) As Long

    Private Declare PtrSafe Function CallNextHookEx Lib "user32" ( _
                                 ByVal hHook As Long, _
                                 ByVal nCode As Long, _
                                 ByVal wParam As Long, _
                                 lParam As Any) As Long

    Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" ( _
                                 ByVal hHook As Long) As Long

    Private Declare PtrSafe Function PostMessage Lib "user32.dll" _
                         Alias "PostMessageA" ( _
                                 ByVal hwnd As Long, _
                                 ByVal wMsg As Long, _
                                 ByVal wParam As Long, _
                                 ByVal lParam As Long) As Long

    Private Declare PtrSafe Function WindowFromPoint Lib "user32" ( _
                                 ByVal xPoint As Long, _
                                 ByVal yPoint As Long) As Long

    Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" ( _
                                 ByRef lpPoint As POINTAPI) As Long

    Private Const WH_MOUSE_LL As Long = 14
    Private Const WM_MOUSEWHEEL As Long = &H20A
    Private Const HC_ACTION As Long = 0
    Private Const GWL_HINSTANCE As Long = (-6)

    Private Const WM_KEYDOWN As Long = &H100
    Private Const WM_KEYUP As Long = &H101
    Private Const VK_UP As Long = &H26
    Private Const VK_DOWN As Long = &H28
    Private Const WM_LBUTTONDOWN As Long = &H201

    Private mLngMouseHook As Long
    Private mListBoxHwnd As Long
    Private mbHook As Boolean

    Sub HookListBoxScroll()
    Dim lngAppInst As Long
    Dim hwndUnderCursor As Long
    Dim tPT As POINTAPI
            GetCursorPos tPT
            hwndUnderCursor = WindowFromPoint(tPT.X, tPT.Y)
            If mListBoxHwnd <> hwndUnderCursor Then
                 UnhookListBoxScroll
                 mListBoxHwnd = hwndUnderCursor
                    lngAppInst = GetWindowLong(mListBoxHwnd, GWL_HINSTANCE)
                    PostMessage mListBoxHwnd, WM_LBUTTONDOWN, 0&, 0&
                 If Not mbHook Then
                         mLngMouseHook = SetWindowsHookEx( _
                                                         WH_MOUSE_LL, AddressOf MouseProc, lngAppInst, 0)
                         mbHook = mLngMouseHook <> 0
                 End If
         End If
    End Sub

    'It shows Compile Error Type MisMatch

    Sub UnhookListBoxScroll()
         If mbHook Then
                 UnhookWindowsHookEx mLngMouseHook
                 mLngMouseHook = 0
                 mListBoxHwnd = 0
                 mbHook = False
         End If
    End Sub

    Private Function MouseProc( _
                 ByVal nCode As Long, ByVal wParam As Long, _
                 ByRef lParam As MOUSEHOOKSTRUCT) As Long
            On Error GoTo errH 'Resume Next
            If (nCode = HC_ACTION) Then
                 If WindowFromPoint(lParam.pt.X, lParam.pt.Y) = mListBoxHwnd Then
                         If wParam = WM_MOUSEWHEEL Then
                                 MouseProc = True
                                 If lParam.hwnd > 0 Then
                                         PostMessage mListBoxHwnd, WM_KEYDOWN, VK_UP, 0
                                 Else
                                         PostMessage mListBoxHwnd, WM_KEYDOWN, VK_DOWN, 0
                                 End If
                                 PostMessage mListBoxHwnd, WM_KEYUP, VK_UP, 0
                                 Exit Function
                         End If
                 Else
                         UnhookListBoxScroll
                 End If
         End If
            MouseProc = CallNextHookEx( _
                                 mLngMouseHook, nCode, wParam, ByVal lParam)
         Exit Function
    errH:
            UnhookListBoxScroll
    End Function

    ' 2. In UserForm

    Private Sub ListBox1_MouseMove( _
               ByVal Button As Integer, ByVal Shift As Integer, _
               ByVal X As Single, ByVal Y As Single)
        HookListBoxScroll
    End Sub


    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        UnhookListBoxScroll
    End Sub
    '*********************************************'''''' end Userform code

    Thanks




    • Edited by smuneeb Friday, November 27, 2015 7:56 AM
    Friday, November 27, 2015 6:47 AM

All replies

  • You have to convert all pointers from being Long (32-bit) to LongPtr (64-bit).  I will tell you I tried to convert a VBA addin from 32-bit to 64-bit and gave up.  You can Google/Bing VBA 32-bit 64-bit.  You will find lots of posting on the subject.  Here are a few:

    Win32API_PtrSafe with 64-bit Support

    Compatibility Between the 32-bit and 64-bit Versions of Office 2010

    For example this:

    Private Declare PtrSafe Function FindWindow Lib "user32" _
                         Alias "FindWindowA" ( _
                                 ByVal lpClassName As String, _
                                 ByVal lpWindowName As String) As Long

    becomes this

    Private Declare PtrSafe Function FindWindow Lib "user32" _
                         Alias "FindWindowA" ( _
                                 ByVal lpClassName As String, _
                                 ByVal lpWindowName As String) As LongPtr


    • Edited by mogulman52 Friday, November 27, 2015 6:52 PM Added links
    Friday, November 27, 2015 6:31 PM