Go Back   Access World Forums > Microsoft Access Reference > Code Repository

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-18-2018, 07:54 PM   #1
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 6,735
Thanks: 55
Thanked 2,143 Times in 2,054 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Win32 API

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.
Attached Files
File Type: zip Win32API_PtrSafe.zip (137.8 KB, 33 views)

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 05-30-2018, 01:13 AM   #2
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,605
Thanks: 90
Thanked 1,619 Times in 1,508 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: Win32 API

@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...sapiviewer.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?L...ion-vba-64-bit. The GetTickCount example is taken from his article
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Web links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 05-30-2018 at 01:27 AM.
isladogs is offline   Reply With Quote
Reply

Tags
a2010 , api , vba , x64

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid Win32 application masenko Windows 3 10-24-2007 11:24 AM
Invalid win32 application shadowraven Windows 3 06-06-2006 02:02 AM




All times are GMT -8. The time now is 02:00 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World