Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading INI using windows api
Message
 
À
10/11/2000 10:57:27
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00440229
Message ID:
00440271
Vues:
12
>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?

About your code: how does strKeyName is declared?

I always use a variable and I never experienced any problems. Here is part of my code:
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 Function ReadFromINI(ByVal pstrSection As String, _
                            ByVal pstrKey As String, _
                            ByVal pstrDefault As String, _
                            ByVal pstrPath As String _
                           ) As String
Dim lngReturn As Long
Dim strReturn As String

    strReturn = String$(200, 0)
    lngReturn = GetPrivateProfileString(pstrSection, pstrKey, pstrDefault, strReturn, Len(strReturn), pstrPath)
    ReadFromINI = Left$(strReturn, lngReturn)
End Function
>>do I need to worry about closing the ini?

No. The API call close it for you.
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform