Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 27: Using the Windows Application Programming Interface


965


GetProfileStringA


GetProfileStringA is very much like GetPrivateProfileStringA.


Declare Function apiGetProfileString _
Lib “Kernel32” _
Alias “GetProfileStringA”( _
ByVal lpszSection As String, _
ByVal lpszKey As String, _
ByVal lpszDefault As String, _
ByVal lpszReturnString As String, _
ByVal dwReturnSize As Long) As Long

This function behaves like GetPrivateProfileStringA, except it does not accept a filename
as an argument. GetProfileStringA works only with the win.ini file, located in the
Windows installation folder. Notice that you don’t have to tell GetProfileStringA where
Windows is installed. GetProfileStringA is able to find the Windows installation folder with-
out any help.


WritePrivateProfileStringA


WritePrivateProfileStringA writes information to a private (application-specific .ini
file):


Declare Function apiWritePrivateProfileString _
Lib “Kernel32” _
Alias “WritePrivateProfileStringA”( _
ByVal lpszSection As String, _
ByVal lpszKey As String, _
ByVal lpszSetting As String, _
ByVal lpszFilename As String) As Long

Like GetPrivateProfileStringA, this function receives a section, KeyName, default,
and filename as arguments. But it also accepts the value you want to place in the .ini file in
the lpszSetting argument. If the function is successful, it returns a nonzero value; otherwise, it
returns zero.


The WritePrivateString() wrapper function writes new title-bar text to a specified .ini file
by using the CurentProject.Path property and using the returned command line, plus the
filename, as the full path to the .ini file:


Sub WritePrivateString()
Dim Section As String
Dim KeyName As String
Dim Value As String
Dim FileName As String
Dim RetVal As Long
Dim Setting As Long
Dim PathName As String
Free download pdf