Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
Reading INI using windows api
I am using the following to read an ini file:
Public Declare Function GetPrivateProfileString 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
Public gstrKeyValue As String * 256
strFileName = "c:\test\test.ini"
strSectionName = "DataSource Info"
strKeyName = "DataSetInfoDir"
lonValueSize = GetPrivateProfileString(strSectionName,_
"DataSetInfoDir", "?!?", gstrKeyValue, 256, strFileName)
vsDir = Left$(gstrKeyValue, lonValueSize)
I have it working properly, the Key value (variable vsDir) is exactly what I expect it to be. The problem that I have is that I want the parameter ByVal lpKeyName As Any to be a variable. Every time I try to send the parameter as a variable (strKeyName) I get a type error. If I hard code lpKeyName it works just fine. What do I dim the variable as for type ANY? I tried a string and that doesn't work.
Also, because I am not actually opening the file for input do I need to worry about closing the ini?
Thanks,
Nichole Brelje
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement