MSOffice convert MSAccess 2010 32-Bit for MSAccess 2013 64-Bit PtrSafe LongPtr (1 Viewer)

Rx_

Nothing In Moderation
Local time
Today, 00:13
Joined
Oct 22, 2009
Messages
2,803
PtrSafe is required for Declare Statements in Office 2013 64-Bit on newer Windows 64-Bit servers. Attempting to make updates to code today.
Any suggestions or questions would be very welcome.
My plan is to use a conditional compile.

Interesting enough, the 64-Bit development Desktop with MSOffice 2010 32-bit with Access 2010 VBA that referenced Excel 2010 code
ran on a Windows 64-bit Server with MSOffice 2010 64 Bit with no issues.
The server is part of a Citrix distribution.

A new Windows Server was set up with Office 2013 64-bit. The same MSAccess 2013 application would not open due to declarations consistent with not having the Declare statements using the PtrSafe.

Have located about a dozen Declare statements in the Front-End project (tied to SQL Server back-end via SQL Server Native Client 11.0.

Found several previous post. After acquiring a VM to develop a 32 bit code and then open it in a 64 bit server, I will start the conversion:
http://www.access-programmers.co.uk/forums/showthread.php?t=281561&highlight=ptrsafe
http://www.access-programmers.co.uk/forums/showthread.php?t=281463&highlight=ptrsafe
http://www.access-programmers.co.uk/forums/showthread.php?t=275117

Bottom line, the PtrSafe did not seem to be enough in some of the cases cited above.
 
Last edited:

Rx_

Nothing In Moderation
Local time
Today, 00:13
Joined
Oct 22, 2009
Messages
2,803
Some of the 32 bit Declare include:
http://allenbrowne.com/func-07b.html
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function CloseClipboard Lib "user32" () As Long

The following seems to be working on the 32-bit Office - will try to run remotely on the 64-Bit OS Server soon
Code:
#If Win64 Then
    'To copy text on the clipboard
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    Private Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongLong) As Long
    Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongLong) As LongPtr
    Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As LongLong) As LongPtr
    Private Declare PtrSafe Function GlobalSize Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
    Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
    Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongLong) As Long
    Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
    Private Declare PtrSafe Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As String) As LongPtr
    Private Declare PtrSafe Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As LongPtr
    Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As LongLong) As LongLong
    Private Declare PtrSafe Function EnumClipboardFormats Lib "user32" (ByVal wFormat As Long) As Long
    Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
  #Else
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
    Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
    Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function EnumClipboardFormats Lib "user32" (ByVal wFormat As Long) As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
  #End If
 

Rx_

Nothing In Moderation
Local time
Today, 00:13
Joined
Oct 22, 2009
Messages
2,803
After successfully addressing dozens of my Win32 API calls, just wanted to share the primary documents and data sources that helped. They lean to Office 2013 programming since my applications use Tools Reference with Remote Automation to create extensive Excel documents as reports, copy/paste, and other features.

The conversion and testing was successful on 64-Bit Server running Office 2013 64-Bit and Windows 7 Enterprise 64-Bit with Office 2010 32-Bit. Soon, my Windows 7 development workstation will use Office 2013 32-Bit.

Useful: This Microsoft article describes the how-to's to properly write the declarations. What is missing is which type declarations go with which API function or sub. This article designed for Office 2010 was very useful:
https://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx

This link will download an API support document from Microsoft:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=9970
Download the file by clicking the Download link (above) and saving the file to your hard disk.
Double-click the Office2010Win32API_PtrSafe program file on your hard disk to start the setup program.
Follow the instructions on the screen to complete the installation.
By Default - it will install on: C:\Office 2010 Developer Resources\Documents\

Microsoft has provided the Win32API.txt with all proper declarations.
An example of many of the API conversions can be found here:
http://www.jkp-ads.com/articles/apideclarations.asp?AllComments=True
 

Users who are viewing this thread

Top Bottom