Solved

VBA: Declarations for 64-bit versions of libraries

Posted on 2016-10-28
3
66 Views
Last Modified: 2016-10-31
I have code that includes declarations of 32-bit Microsoft libraries.  Some of our users are now just migrating to 64-bit versions of Office and I want the code to work on both.  I tried to look around for the 64-bit equivalents of the 32-bit declarations, but no luck.  Our code works for those running MS Access 2010 but not MS Access 2013 64-bit.

Any help would be much appreciated.  Here are the 32-bit declarations:

Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function AddPrinterConnection Lib "winspool.drv" Alias "AddPrinterConnectionA" (ByVal pName As String) As Long
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
0
Comment
Question by:koughdur
3 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
ID: 41864748
you need to  add PtrSafe in the declaration and the value LongPtr is used instead of Long

in 32 bit you will declare
Declare Function GetActiveWindow Lib "User32" () As Long

in 64 bit use
Declare PtrSafe Function GetActiveWindow Lib "User32" () As LongPtr


see these links for more information
Declare64bit
Declare64bit_1
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 41864830
Sounds like you are on your way, but here are some things that will help:

This is an overview.  Make sure you read the section "Introducing the VBA 7 Code Base"

Compatibility Between the 32-bit and 64-bit Versions of Office 2010
http://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx


There is also a code inspector for 64 bit:

Microsoft Office Code Compatibility Inspector user's guide
http://technet.microsoft.com/en-us/library/ee833946.aspx

 which will tell you what needs to be changed.

Here is a list of all the new 64 bit calls:

http://www.microsoft.com/download/en/confirmation.aspx?displaylang=en&id=9970

and here's a list of all the calls that were modified for 64 bit:
http://msdn.microsoft.com/en-us/library/aa383663(VS.85).aspx

Jim.
0
 

Author Closing Comment

by:koughdur
ID: 41867004
Thank you SOOOO much!  This is all very helpful.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now