Win32 API (1 Viewer)

Status
Not open for further replies.

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:50
Joined
May 7, 2009
Messages
19,169
attached is the 64 bit declarations of windows API.
since many in the forum wanted to convert some VBA with API to correct
declaration.
if the API you are searching is not on the list, it's probably did not came together with Windows, meaning from a third party software you installed.

template for coding in your VBA:
Code:
#if VBA7
	' newer version of access (A2010 and newer)
	#if Win64
		' if you are running a 64 bit office
		' should use PtrSafe and LongPtr
	#else
		' 32 bit
		' should use PtrSafe and Long
	#end if
#else
	' older version
	' without PtrSafe and with Long
#end if

changing the declaration does not guarantee that the sub/function will work.
you have to check each variable declarations on each line of code.
making sure it adhere or same as declared in your API declaration.
 

Attachments

  • Win32API_PtrSafe.zip
    137.8 KB · Views: 304

isladogs

MVP / VIP
Local time
Today, 15:50
Joined
Jan 14, 2017
Messages
18,186
@arnelgp
Thanks for the attached list of APIs which I have stored for future reference. Can I ask where you got it from.

I also recommend the WinAPI Viewer by Ron de Bruin https://www.rondebruin.nl/win/dennis/windowsapiviewer.htm
This lists a large number of APIs in both 32-bit & 64-bit versions. Its listed as 'for Excel' but is equally useful in Access

Your template for conditional compiling for 32/64 bit systems is one valid method. Two other ways with examples:

Code:
#If VBA7 Then  'use PtrSafe
   Declare PtrSafe Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

#ElseIf Win64 Then 'use PtrSafe & datatype LongPtr for pointers
    Declare PtrSafe Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As LongPtr) As Long
    
#Else '32-bit Office
    Declare Ptr Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

#End If

Unless your code also needs to run in Access versions before A2010 this can be simplified to:

Code:
#If VBA7 Then  'use PtrSafe
   Declare PtrSafe Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As LongPtr) As Long
   
#Else '32-bit Office
    Declare Ptr Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As Long

#End If

However some API functions do not work in 64-bit e.g. GetTickCount used to measure system time since startup. For those, you need to reference the 64-bit constant e.g.

Code:
#If Win64 Then
    Public Declare PtrSafe Function GetTickCount Lib "Kernel32" Alias "GetTickCount64" () As LongPtr
#Else
    Public Declare PtrSafe Function GetTickCount Lib "Kernel32" () As LongPtr
#End If

Phillip Stiefel (sonic8) has done a very good guide to managing 32/64 bit compilation issues at: http://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit. The GetTickCount example is taken from his article
 
Last edited:
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom