Advanced: Requires expert coding, interoperability, and multiuser skills.
Because the architecture of Windows 95 and later and Windows NT is 32-bit,
there are several differences in the application programming interface
(API) from the 16-bit API of Windows 3.x. This article shows you how to
convert code that contains 16-bit API calls to 32-bit API calls so that the
code will run successfully in a 32-bit operating environment. This article
discusses the following topics:
Why 16-bit API calls do not work in a 32-bit operating environment
Tips on how to make the conversion process easier
List of converted declaration statements for common API functions
that you can copy into your modules.
Parameter data types are often different, for example:
16-bit 32-bit
-------------------
Integer Long
Integer Byte
Double Long
NOTE: This is not a complete list. You should watch closely for
different parameter data types when you convert code that makes an API
call or supplies parameters to an API call.
API function names are case-sensitive. This differs from the 16-bit API,
which is not case-sensitive. For example, in a 16-bit API call, the
following statements are equivalent:
Declare Function GetVersion Lib "KERNEL" () as Long
Declare Function gEtVeRsIoN Lib "KERNEL" () as Long
However, when converted to a 32-bit API, the following statements are
not equivalent because the function names are case-sensitive:
Declare Function GetVersion Lib "KERNEL32" () as Long
Declare Function gEtVeRsIoN Lib "KERNEL32" () as Long
Some API functions have different versions to accommodate ANSI and
UniCode strings. If an API listed in this article is limited to use
under a specific operating system in 32-bit, it will be noted with
the API function.
You can reduce the work involved with converting your existing code by
adopting these practices:
When you declare an API procedure, use an alias for the procedure
name. The alias must be unique from the function name. If it is not,
the alias will be deleted automatically.
When you declare the data type returned by the function or the data
type of parameters passed to the function, use an As clause rather
than the type declaration characters (%, $, and so on).
There is also a helpful utility included with the Microsoft Access
Developers Toolkit for Windows 95, Microsoft Office 97 Developer Edition,
and Visual Basic 4.0 that makes working with APIs easier. It is called the
API Viewer. It enables you to browse through Declares, Constants, and
Types that are included in any text file or in a Microsoft Jet database
that contains API information. You can copy these items to the Clipboard
and then paste them into your code.
List of Converted Declaration Statements for Common API Functions
Following is a listing of 16-bit and 32-bit Declare statements for common
API calls that you can use as reference when you convert your code to
32-bit.
NOTE: If you use any of the following 16-bit declarations in Microsoft
Access 2.0 or earlier, an underscore (_) at the end of a line is used
as a line-continuation character. Remove the underscore from the end of
the line when re-creating these declarations.
Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, _
ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As _
Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As _
Long) As Long
32-bit:
Declare Function apiBitBlt Lib "gdi32" Alias "BitBlt" (ByVal _
hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth _
As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal _
XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Declare Function CheckMenuItem Lib "User" (ByVal hMenu As _
Integer, ByVal wIDCheckItem As Integer, ByVal wCheck As _
Integer) As Integer
32-bit:
Declare Function apiCheckMenuItem Lib "user32" Alias _
"CheckMenuItem" (ByVal hMenu As Long, ByVal wIDCheckItem _
As Long, ByVal wCheck As Long) As Long
NOTE: In Microsoft Access for Windows 95 version 7.0, you can use the
SetMenuItem macro action to set the state of menu items (enabled or
disabled, checked or unchecked) on a custom menu bar or the global menu
bar for the active window. For more information about the SetMenuItem
action, search the Help Index for "SetMenuItem Action."
In Microsoft Access 97, you can use the SetMenuItem macro action only
with custom menu bars and global menu bars created by using menu bar
macros. The SetMenuItem action is included in Microsoft Access 97 for
compatibility with earlier versions. To implement the same functionality
with the CommandBars collection in Microsoft Access 97, use the Enabled
and State properties of command bars in Visual Basic for Applications to
enable or disable, check or uncheck items on menu bars, toolbars, and
shortcut menus. For more information about these properties, search the
Help Index for "Enabled" or "State," or ask the Microsoft Access 97
Office Assistant.
Declare Function ChooseColor_API Lib "COMMDLG.DLL" Alias _
"ChooseColor" (pCHOOSECOLOR As ChooseColor) As Integer
32-bit:
Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
RgbResult As Long
lpCustColors As Long
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long
End Type
Declare Function apiChooseColor Lib "comdlg32.dll" Alias _
"ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
NOTE: You can use the ChooseColor functionality of this API by using
the Common Dialog ActiveX control included with the Microsoft Access
Developer's Toolkit for Windows 95 and Microsoft Office 97 Developer
Edition.
Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As _
String, ByVal bFailIfExists As Long) As Long
NOTE: File attributes (FILE_ATTRIBUTE_*) for the existing file are copied
to the new file. For example, if an existing file has the
FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to
CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For
further information on file attributes, see CreateFile.
NOTE: To achieve the same results, you can use the FileCopy Statement from
within Microsoft Access 7.0 or 97.
Declare Sub hmemcpy Lib "kernel" (hpvDest As Any, hpvSrc As _
Any, ByVal cbBytes As Long)
32-bit:
Global Const GMEM_MOVEABLE = &H2
Global Const GMEM_ZEROINIT = &H40
Global Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Declare Function CreateCompatibleBitmap Lib "GDI" (ByVal _
hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As _
Integer) As Integer
32-bit:
Declare Function apiCreateCompatibleBitmap Lib "gdi32" Alias _
"CreateCompatibleBitmap" (ByVal hdc As Long, ByVal nWidth As _
Long, ByVal nHeight As Long) As Long
Declare Function EnableMenuItem Lib "User" (ByVal hMenu As _
Integer, ByVal wIDEnableItem As Integer, ByVal wEnable _
As Integer) As Integer
32-bit:
Declare Function apiEnableMenuItem Lib "user32" Alias _
"EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableItem _
As Long, ByVal wEnable As Long) As Long
Declare Function FindExecutable Lib "Shell" (ByVal _
lpszFile As String, ByVal lpszDir As String, ByVal _
lpszResult As String) As Integer
32-bit:
Declare Function apiFindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory _
As String, ByVal lpResult As String) As Long
Declare Function GetClassName Lib "User" (ByVal hWnd _
As Integer, ByVal lpClassName As String, ByVal nMaxCount _
As Integer) As Integer
32-bit:
Declare Function apiGetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Declare Function GetFileVersionInfo Lib "VER.DLL" _
(ByVal lpszFileName As String, ByVal lpdwHandle As Long, _
ByVal cbbuf As Long, ByVal lpvdata As String) As Integer
32-bit:
Declare Function apiGetFileVersionInfo Lib "version.dll" _
Alias "GetFileVersionInfoA" (ByVal lptstrFilename As _
String, ByVal dwHandle As Long, ByVal dwLen As Long, _
lpData As Any) As Long
Declare Function GetFileVersionInfoSize Lib "VER.DLL" _
(ByVal lpszFileName As String, lpdwHandle As Long) As Long
32-bit:
Declare Function apiGetFileVersionInfoSize Lib _
"version.dll" Alias "GetFileVersionInfoSizeA" _
(ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Declare Function GetModuleFileName Lib "Kernel" (ByVal _
hModule As Integer, ByVal lpFilename As String, ByVal _
nSize As Integer) As Integer
32-bit:
Declare Function apiGetModuleFileName Lib "kernel32" Alias _
"GetModuleFileNameA" (ByVal hModule As Long, ByVal _
lpFileName As String, ByVal nSize As Long) As Long
Declare Function GetOpenFileName Lib "COMMDLG.DLL" _
(OPENFILENAME As tagOPENFILENAME) As Integer
32-bit:
Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OPENFILENAME as tagOPENFILENAME) _
As Long
Declare Function GetPrivateProfileString Lib "Kernel" _
(ByVal lpApplicationName As String, ByVal lpKeyName As _
Any, ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
32-bit:
Declare Function apiGetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName _
As String, ByVal lpKeyName As Any, ByVal lpDefault As _
String, ByVal lpReturnedString As String, ByVal nSize As _
Long, ByVal lpFileName As String) As Long
Declare Function GetSaveFileName Lib "COMMDLG.DLL" _
(OPENFILENAME As tagOPENFILENAME) As Integer
32-bit:
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As Long
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (pOpenfilename as OPENFILENAME) _
As Long
NOTE: You can achieve the same functionality with the Common Dialog
OLE control included with the Microsoft Access Developer's Toolkit for
Windows 95 and Microsoft Office 97 Professional Edition.
Declare Sub GetWindowRect Lib "GDI" (ByVal hWnd As _
Integer, lpRect As RECT)
32-bit:
Type RECT_Type
left As Long
top As Long
right As Long
bottom As Long
End Type
Declare Function apiGetWindowRect Lib "user32" Alias _
"GetWindowRect" (ByVal hwnd As Long, lpRect As RECT_Type) _
As Long
Declare Function NetWkstaGetInfo Lib "NetAPI.DLL" _
(ByVal lServer As Long, ByVal sLevel As Integer, _
ByVal pbBuffer As Long, ByVal cbBuffer As Integer, _
pcbTotalAvail As Integer) As Integer
32-bit:
Declare Function apiNetWkstaGetInfo Lib "NetAPI32.dll"_
Alias NetWkstaGetInfo (ByVal lServer as Integer, ByVal _
sLevel as Integer, ByVal pbBuffer as Long, cbBuffer as _
Integer, pcbTotalAvail as Integer) As Integer
NOTE: This function is available only in the Windows NT environment.
NOTE: In Microsoft Access 7.0 and 97, you can use the CurrentUser()
function to obtain the currently logged on user.
Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer,_
ByVal hWndInsertAfter As Integer, ByVal X As Integer, _
ByVal Y As Integer, ByVal cx As Integer, ByVal cy _
As Integer, ByVal wFlags As Integer)
32-bit:
Declare Function apiSetWindowPos Lib "user32" Alias _
"SetWindowPos" (ByVal hwnd As Long, ByVal _
hWndInsertAfter As Long, ByVal x As Long, ByVal y _
As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Declare Function ShellExecute Lib "SHELL" (ByVal _
hwnd As Integer, ByVal lpszOp As String, ByVal lpszFile _
As String, ByVal lpszParams As String, ByVal lpszDir As _
String, ByVal fsShowCmd As Integer) As Integer
32-bit:
Declare Function apiShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
String, ByVal lpFile As String, ByVal lpParameters As _
String, ByVal lpDirectory As String, ByVal nShowCmd As _
Long) As Long
Declare Function WNetAddConnection Lib "User" (ByVal _
lpszNetPath As String, ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Integer
32-bit:
Declare Function apiWNetAddConnection Lib "mpr.dll" Alias _
"WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal _
lpszPassword As String, ByVal lpszLocalName As String) As Long
Declare Function WNetGetUser Lib "USER.EXE" (ByVal _
szUser As String, lpnBufferSize As Integer) As Integer
32-bit:
Declare Function apiWNetGetUser Lib "mpr.dll" Alias _
"WNetGetUserA" (ByVal lpName As String, ByVal _
lpUserName As String, lpnLength As Long) As _
Long
Declare Function WNetGetUser Lib "mpr" Alias _
"WNetGetUserA" (ByVal lpName As String, ByVal _
lpUserName As String, lpnLength As Long) As Long
Declare Function WritePrivateProfileString Lib _
"Kernel" (ByVal lpApplicationName As String, ByVal _
lpKeyName As Any, ByVal lpString As Any, ByVal _
lplFileName As String) As Integer
32-bit:
Declare Function apiWritePrivateProfileString Lib _
"kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName _
As Any, ByVal lpString As Any, ByVal lpFileName As _
String) As Long
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.