Microsoft KB Archive/97515

= ACC: Passing a Null Pointer to an External DLL =

Article ID: 97515

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q97515



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 &quot;Building Applications with Microsoft Access&quot; 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 &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x or the &quot;Building Applications&quot; 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 &quot;kernel32.&quot; '==================================================================

Declare Function writeprofilestring Lib &quot;Kernel32&quot; Alias &quot; _ WriteProfileStringA&quot;(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 &quot;kernel.&quot; '==================================================================

Declare Function writeprofilestring Lib &quot;Kernel&quot; Alias &quot; _ WriteProfileString&quot;(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

Keywords: kbinfo kbprogramming KB97515

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.