Solved

VBA: Declarations for 64-bit versions of libraries

Posted on 2016-10-28
3
38 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

708 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

12 Experts available now in Live!

Get 1:1 Help Now