K

- Base de connaissances

Accueil > API WINDOWS > WritePrivateProfileString

WritePrivateProfileString

mercredi 5 décembre 2012, par webmestre

Fichier DLL : kernel32.dll

Prototype VB6/VBA :

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'--------------------------------
'------Déclaration des APIs------
'--------------------------------
'---Gestion du ficheir INI---
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'--------------------------------------------------------------------------
'------Fonctions de gestion de fichiers de configuration .INI (WIN32)------
'--------------------------------------------------------------------------
Public Function IniFile_Read(lpApplicationName As String, lpKeyName As String, lpFileName As String, Optional lpDefault As String = "") As String
    '---Déclaration des cosntantes---
    Const lenBuffer As Long = 1000 ' caractères
   
    '---Déclaration des variables---
    Dim lpReturnedString As String
    Dim nSize As Long
    Dim lgRep As Long
   
    '---Initialisation du buffer---
    lpReturnedString = String(lenBuffer, Chr$(0))
    nSize = lenBuffer
   
    '---Lecture de la clef "lpKeyName" dans la section "lpApplicationName"---
    lgRep = GetPrivateProfileString(lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)
    IniFile_Read = Left$(stBuf, lgRep)
End Function
Public Function IniFile_Write(lpApplicationName As String, lpKeyName As String, lpFileName As String, lpString As String) As Boolean
    '---Ecrire dans le fichier---
    IniFile_Write = WritePrivateProfileString(lpApplicationName, lpKeyName, lpString, lpFileName)
End Function

Répondre à cet article

Plan du site | Suivre la vie du site RSS 2.0 | powered by NYSTEK-EDITIONS and NYSTEK-CONSULTING