MS ACCESS 2013 32bit to 64bit

Well we are back to square one? :(

That would infer to me that MouseHookAddr needs to be LongPtr and not Long? Perhaps even the size needs to be Long, but cross that bridge if/when you come to it.

I also did a Google and found this from this search

So you have a lot more work to do it seems?
 
e into the allocated memoryA[/CODE]

It says Compile error Type mismatch







Maybe there was a mixup. The actual line is the following line

Code:
           Call CopyMemoryAnsi(MouseHookAddr, NativeCode, Len(NativeCode))

It says Compile error Type mismatch and highlights "MouseHookAddr"


I repeat the entire module except the Native Code because it was too big. I just assigned NativeCode = "123"

Code:
Option Compare Database
Option Explicit

'   *****************************************************************************
'   * ------------      MOUSE HOOK for Microsoft(r) Access VBA     ------------ *
'   * ------------      (c) Wayne Phillips / iTech Masters 2009    ------------ *
'   * ------------          http://www.everythingaccess.com        ------------ *
'   *****************************************************************************
'   *                                                                           *
'   * This module exposes a function that creates an in-memory, COM-compatible  *
'   * object that is written in native x86 code rather than VBA.                *
'   *                                                                           *
'   * The purpose of this module is to allow easy disabling of the mouse scroll *
'   * wheel in Forms, without needing a DLL and without VBA problems usually    *
'   * associated with subclassing windows:                                      *
'   * http://support.microsoft.com/?kbid=278379                                 *
'   *                                                                           *
'   * - v1.2 28/08/2009 - now compatible with both VBA5 and VBA6 (Access 97+)   *
'   * - v1.4 01/09/2009 - Scroll disabled by default, for convenience           *
'   * - v1.5 04/12/2009 - now the methods Init and Scroll are case insensitive  *
'   *                                                                           *
'   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
'   * All the benefits of using a native compiled DLL - without needing a DLL!  *
'   *                                                                           *
'   *   You are free to include this module in your project provided that you   *
'   *  leave this copyright notice in place and that no modifications are made. *
'   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
'   * Instructions:                                                             *
'   *                                                                           *
'   *  Add the following code to your OnOpen event:                             *
'   *                                                                           *
'   *     Private Sub Form_Open(Cancel As Integer)                              *
'   *         Static MouseHook As Object                                        *
'   *         Set MouseHook = NewMouseHook(Me)                                  *
'   *     End Sub                                                               *
'   *                                                                           *
'   *****************************************************************************

Private Declare Function VirtualAlloc Lib "kernel32" (ByVal Address As Long, ByVal Size As Long, ByVal AllocationType As Long, ByVal Protect As Long) As Long
Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal ProcName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal Module As Long, ByVal ProcName As String) As Long
Private Declare Sub CopyMemoryAnsi Lib "kernel32" Alias "RtlMoveMemory" (ByVal Dest As Long, ByVal Source As String, ByVal Size As Long)
Private Declare Sub CastToObject Lib "kernel32" Alias "RtlMoveMemory" (ByRef Dest As Object, ByRef Source As Long, ByVal Size As Long)

Private Const SIZEOF_PTR32              As Long = &H4
Private Const PAGE_EXECUTE_RW           As Long = &H40
Private Const MEM_RESERVE_AND_COMMIT    As Long = &H3000
Private Const ERR_OUT_OF_MEMORY         As Long = &H7

Private Type IDispatchVTable
    QueryInterface As Long
    AddRef As Long
    Release As Long
    GetTypeInfoCount As Long
    GetTypeInfo As Long
    GetIDsOfNames As Long
    Invoke As Long
End Type

Public Function NewMouseHook(ByRef Form As Access.Form) As Object

    Dim NativeCode As String
    Dim Kernel32Handle As Long
    Dim GetProcAddressPtr As Long
    Dim MouseHookAddr As Long
    Dim MouseHookLoader As Object
    Dim LoaderVTable As IDispatchVTable
         
    NativeCode = "123"
         
    ' Allocate the executable memory for the object
        MouseHookAddr = VirtualAlloc(0, Len(NativeCode), MEM_RESERVE_AND_COMMIT, PAGE_EXECUTE_RW)

    If MouseHookAddr <> 0 Then
 
        ' Copy the x86 native code into the allocated memory
            Call CopyMemoryAnsi(MouseHookAddr, NativeCode, Len(NativeCode))
           
        ' Force the memory address into an Object variable (also triggers the shell code)
            LoaderVTable.QueryInterface = MouseHookAddr
            Call CastToObject(MouseHookLoader, VarPtr(VarPtr(LoaderVTable)), SIZEOF_PTR32)
            If Not TypeOf MouseHookLoader Is VBA.Collection Then
                Set NewMouseHook = (MouseHookLoader)
                Set MouseHookLoader = Nothing
            End If
         
        ' Initialize our COM object
            Kernel32Handle = GetModuleHandleA("kernel32")
            GetProcAddressPtr = GetProcAddress(Kernel32Handle, "GetProcAddress")
            Call NewMouseHook.Init(Kernel32Handle, GetProcAddressPtr, Form.hwnd)
         
        ' Disable the scroll wheel by default.
            NewMouseHook.Scroll = False
     
    Else
 
        Err.Raise ERR_OUT_OF_MEMORY
 
    End If
 
End Function
[/QUOTE]
Well we are back to square one? :(

That would infer to me that MouseHookAddr needs to be LongPtr and not Long? Perhaps even the size needs to be Long, but cross that bridge if/when you come to it.

I also did a Google and found this from this search

So you have a lot more work to do it seems?
Many thanks.

I might employ the nuclear option of removing the code from my software. Will try to fix the problem to get more educated on the matter.

I took pride in not using any third party software for developing the software. I guess the specific module crept in.
 
I would just comment it out for now.
But it takes less than 10 seconds to change Long to LongPtr and try a compile?
 
If that doesn't work, I suggest you contact Wayne Phillips direct. Only he will know what the NativeCode section comprises
 
If that doesn't work, I suggest you contact Wayne Phillips direct. Only he will know what the NativeCode section comprises
Will try to contact Wayne. In the mean time I will remove the code from my software. A good case for not using third party software, which you do not fully understand.
 
The reply from Wayne

Hello John,

Unfortunately the mouse hook is not at all 64-bit compatible.

In general, the mouse hook is no longer required, and so the code can usually just be removed.

Kind regards
Wayne Phillips
 
I managed to complete the conversion of my product and it appears to work.

I was not able to find the following APIs and I simply added a "PtrSafe"

Any ideas?


Code:
Public Declare Function ezGetFileInfo Lib "msaccess.exe" _
     Alias "#56" (FSI As ezFileSelInfo, ByVal fOpen As Integer) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" _
   (ByVal pidl As Long, ByVal pszPath As String) As Long

Public Declare Function SHGetSpecialFolderLocation Lib _
   "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
   As Long, pidl As ITEMIDLIST) As Long


Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pidl As Long, _
            ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
            As Long

Public Declare Function InternetGetConnectedState Lib "wininet" _
  (ByRef dwFlags As Long, _
   ByVal dwReserved As Long) As Long

Declare Function GetUserDefaultLCID% Lib "kernel32" ()

Private Declare Function apiFindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal strClass As String, _
    ByVal lpWindow As String) As Long

Private Declare Function apiSendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal _
    wParam As Long, lParam As Long) As Long

Private Declare Function apiSetForegroundWindow Lib "user32" Alias _
    "SetForegroundWindow" (ByVal hwnd As Long) As Long

Private Declare Function apiShowWindow Lib "user32" Alias _
    "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long



Private Declare Function apiIsIconic Lib "user32" Alias _
    "IsIconic" (ByVal hwnd As Long) As Long



Declare Function DllRegisterServer Lib "msadox.dll" () As Long
 
Window handle should be declared as LongPtr.
 
After many changes I managed to convert my old (1997) Access application from 32bit to 64bit. It seems to be running well under 64bit, but will have a eye out for any problems.

For anyone looking to go through the same exercise, I would suggest viewing the first two videos suggested in #2 above. When I could not find the Declaration in the apiviewer suggested in the second video, I needed to follow the field-by-field declaration suggested in the first video.

Many thanks to everyone for their help.
 

Users who are viewing this thread

Back
Top Bottom