ACC: Passing a Null Pointer to an External DLL
ID: Q97515
|
The information in this article applies to:
-
Microsoft Access versions 1.0, 1.1, 2.0, 7.0
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
The Null value is a valid or required parameter for some dynamic-link
libraries (DLLs). To specify a Null value, use 0&.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft
Access versions 1.x and 2.0. For more information about Access Basic,
please refer to the "Introduction to Programming" manual in Microsoft
Access version 1.x or the "Building Applications" manual in Microsoft
Access version 2.0
MORE INFORMATION
When your procedure calls a function and passes the expression 0&, the
ampersand (&) specifies a 32-bit (far) Null pointer. In a function
declaration, an As Any parameter instructs Visual Basic (or Access Basic)
to omit type checking for that parameter and to pass the value to the
called function.
The following code demonstrates the correct method to declare a function
that passes a Null parameter to a function in a DLL. Open a new module or
edit a previously created module to contain the following code.
NOTE: You may have some Microsoft Windows API functions defined in an
existing Microsoft Access library; therefore, your declarations may be
duplicates. If you receive a duplicate procedure name error message, remove
or comment out the declarations statement in your code.
NOTE: In the following sample code, 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 this code in Access Basic.
'*********************************************************************
'Declarations section of the module.
'*********************************************************************
Option Explicit
' In Microsoft Access version 7.0 only:
'==================================================================
' Declare the WriteProfileStringA API function from the external
' Windows dynamic-link library "kernel32."
'==================================================================
Declare Function writeprofilestring Lib "Kernel32" Alias " _
WriteProfileStringA"(ByVal lpApplicationName As Any,ByVal lpKeyName _
As Any,ByVal lpString As Any) as Long
' In Microsoft Access versions 1.x and 2.0 only:
'==================================================================
' Declare the WriteProfileString API function from the external
' Windows dynamic-link library "kernel."
'==================================================================
Declare Function writeprofilestring Lib "Kernel" Alias " _
WriteProfileString"(ByVal lpApplicationName As Any,ByVal lpKeyName _
As Any,ByVal lpString As Any) as Integer
' All versions:
'===================================================================
' Create the following FlushIniCache%() function in the Module. The
' following function calls the external function, specifying null
' for each argument. This causes writeprofilestringa to flush its
' internal cache and writes to disk any changes to WIN.INI. NOTE:
' Using this function incorrectly can cause a general protection
' fault or modify your WIN.INI file. This function returns a False
' if used to flush the cache or if errors are encountered.
'===================================================================
Function FlushIniCache%()
FlushIniCache = writeprofilestring (0&, 0&, 0&)
End Function
Additional query words:
Keywords : kbprg
Version : WINDOWS:1.0,1.1,2.0,7.0
Platform : WINDOWS
Issue type : kbinfo