Cherche code pour les API de PrivateProfile

WolfKiller - 13 sept. 2001 à 14:49
 Gally - 14 sept. 2001 à 13:07
Bonjour, :shy)

Je recherche du code pour les fonction API de Get et Write -PrivateProfile.Elles servent à lire et écrire dans les fichiers ini.

Toute réponse méritent une réponse ;)

Merci d'avance :)

4 réponses

Bonjour,
Facile, tu vas dans Le menu Complement et dans le gestionnaire de complement,tu choisit la Visionneuse d'API.
Elle te donne la déclaration des fonction avec tout ce qui va bien. :clown)
Tchao,pied-plats.
0
Salut,
Merci cassiopee :)

Maintenant mon probleme se situe au niveau de la lecture avec la fonction GetPrivateProfileString qui me plante VB,en me signalant quand même qu'il est interdit et impossible d'écrire dans la mémoire &h000000.

Trop chaud!!!

Une réponse pour m'aider :question)
@+
0
-------------------------------
Réponse au message :
-------------------------------

Salut a tous ;)
J'avoue je me suis cramer tous seul (cf : msg precedent)

Pour me faire pardonner voila mon travail de la journee(pas complete :) )
[codeVB]
Option Explicit

Const bDebug = False

Const gNomFichier = "C:MonFichier.ini"
Const gSection = "\MASECTION"
Const gSize = 80

'Nom des key passe en parametre
'Passer directement une string
'enum est un pense-bete
Public Enum eKey
PARAM_NOM_UTILISTEUR
PARAM_PRENOM_UTILISTEUR
PARAM_SCORE
PARAM_NIVEAU
End Enum

'------------------------------------
' declaration des API de Profile
'------------------------------------
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

'----------------------------------------------------
Public Function Lecture(ByVal sKey As string) As String

Dim retour As Long 'retour de la fonction API : gestion des erreurs
Dim sDefault As String 'Phrase de retour par default
Dim strRetour As String 'la réponse de l'API

sDefault = "Erreur WolfKiller ;-)"
strRetour = String$(gSize, 0) 'SUPER IMPORTANT sinon plante l'API et VB

'Utilisation de l'API
retour = GetPrivateProfileString(gSection, sKey, sDefault, strRetour, gSize, gNomFichier)
If bDebug Then MsgBox ("Retour : " + strRetour)
Lecture = strRetour
End Function

'---------------------------------------------------------------------------
Public Function Ecriture(ByVal sKey As string, ByVal sEcrit As String) As Long
Dim retour As Long

'Utilisation de l'API
retour = WritePrivateProfileString(gSection, sKey, sEcrit, gNomFichier)
If bDebug Then MsgBox ("Ecriture effectuée ")
Ecriture = retour
End Function
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
's'utilise comme dans cet exemple (form avec un textbox et 2 bouton de commande)

Public Enum bBouton
Lecture = 0
Ecriture = 1
End Enum
'---------------------------------------------------------------------
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case Lecture
Text1.Text = modFichierIni.Lecture(PARAM_SCORE)
Case Ecriture
modFichierIni.Ecriture (PARAM_SCORE), Text1.Text
End Select
End Sub

[\codeVb]
Amuser-vous bien avec ça
@+ :clown)
0
Hello,

Comme j'ai déjà fait une petite routine en utilisant l'API PrivateProfile, un tours de magie et la voici...

A++

PS: en cas de prob(s), laisse un message en indiquant comme sujet "PrivateProfile...".

Option Explicit

' Déclaration du tableau des Property.
Private Type Property
Property As String
Value As String
End Type

' Déclaration pour l'Utilisation des INI.
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
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
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

' Déclaration des variables de l'INI.
Public strINI_APPFILE As String
Public strUSERName As String
Public strSociete As String
Public strRegistred As String
Public strLOADPath As String
Public strSAVEPath As String
Public strWordDot As String
Public strProterty() As Property

Public Sub Initialisation()
' Déclarations des variables.
Dim intNb As Integer
Dim lngPos As Long
Dim strTemp01 As String
Dim strTemp02 As String

strINI_APPFILE = App.Path + "" + App.EXEName + ".ini"

If FileExist(strINI_APPFILE) Then

ReDim strProterty(0)

' Lecture de la "Configuration générale".
strUSERName = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "USERName"))
strSociete = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "Societe"))
strRegistred = Decoder(LectureINI(strINI_APPFILE, "GENERAL", "Registred"))
strLOADPath = LectureINI(strINI_APPFILE, "GENERAL", "LOADPath")
strSAVEPath = LectureINI(strINI_APPFILE, "GENERAL", "SAVEPath")
strWordDot = LectureINI(strINI_APPFILE, "GENERAL", "WordDot")

' Lecture de la "Configuration property".
Do
strTemp01 = LectureINI(strINI_APPFILE, "PROPERTYSCAN", "Property" & Trim(Str(intNb)))

If strTemp01 = "" Then
Exit Do
Else
lngPos = InStr(strTemp01, "")
strTemp02 = Mid$(strTemp01, 1, lngPos - 1)
strTemp01 = Mid$(strTemp01, lngPos + 1, Len(strTemp01) - lngPos)

ReDim Preserve strProterty(intNb)
strProterty(intNb).Property = strTemp02
strProterty(intNb).Value = strTemp01
intNb = intNb + 1
End If
Loop

End If
If strUSERName "" Then strUSERName "??" If strSociete "" Then strSociete "??" If strRegistred "" Then strRegistred "??"

End Sub

Public Function LectureINI(ByVal Fichier As String, ByVal Section As String, ByVal Cle As String)
' Lecture du fichier INI et de la Clef.
Dim Valeur As String
Dim Res As Integer
Dim Message As String

Valeur = Space(255)
Res = GetPrivateProfileString(Section, Cle, "", Valeur, Len(Valeur), Fichier)

If Res <> 0 Then
LectureINI = Left(Valeur, Res)
End If

End Function

Public Function EcritureSection(ByVal sNomSection As String, ByVal sValeur As String, ByVal sFileName As String) As Long
' Ecriture de Valeur dans le fichier INI.
EcritureSection = WritePrivateProfileSection(sNomSection, sValeur, sFileName)

End Function

Public Function EcritureINI(ByVal sSection As String, ByVal sKeyName As String, ByVal sNewString As String, sFileName) As Integer
' Ecriture de Clefs et Valeur dans le fichier INI.
Dim Res As Integer

Res = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)

End Function

Public Function Encoder(Text As String) As String
Encoder = Text
End Function

Public Function Decoder(Text As String) As String

Decoder = NewText

End Function
0
Rejoignez-nous