VB.NET et GetPrivateProfileStringA

Résolu
sroz Messages postés 9 Date d'inscription jeudi 3 mars 2005 Statut Membre Dernière intervention 19 juin 2007 - 24 mars 2005 à 16:05
sroz Messages postés 9 Date d'inscription jeudi 3 mars 2005 Statut Membre Dernière intervention 19 juin 2007 - 29 mars 2005 à 14:46
Bonjour à tous,

j'ai un problème avec la méthode GetPrivate PRofileStringA en Vb.net.

Voici mon code :



Private 
Declare 
Function GetPrivateProfileString 
Lib "kernel32" 
Alias "GetPrivateProfileStringA" ( 
ByVal lpApplicationName 
As 
String, 
ByVal lpKeyName 
As 
String, 
ByVal lpDefault 
As 
String, 
ByVal lpReturnedString 
As 
String, 
ByVal nSize 
As 
Long, 
ByVal lpFileName 
As 
String) 
As 
Long







Private Sub act_Lire()
   Dim lsLogin As String
   lsLogin = ini_Lire("OPTIONS", "Login")
End Sub

'** Lecture d'une valeur dans un fichier du type .INI
Public 
Function ini_Lire(
ByVal psSection 
As 
String, 
ByVal psCle 
As 
String) 
As 
String

Dim lnTaille 
As 
Long
Dim lsValeur 
As 
String
Dim lsFichier 
As 
String


lsFichier = System.AppDomain.CurrentDomain.BaseDirectory
If lsFichier.LastIndexOf("") = sFichier.Length - 1 
Then
   lsFichier= lsFichier& "FicProjet.ini"

Else
   lsFichier= lsFichier& "\FicProjet.ini"

End 
If


lsValeur = StrDup(1024, Chr(0))


lnTaille = GetPrivateProfileString(psSection, psCle, "", lsValeur, lsValeur.Length, sFichier)


If lnTaille = 0 
Then
ini_Lire = ""

Else
   ini_Lire = Left(lsValeur.ToString, lnTaille)

End 
If



End 
Function


[Fichier Ini]
[OPTIONS]
Login=SMITH John
Ini

Quand j'exécute la méthode act_Lire, et que je suis l'exécution, la valeur retournée pour lnTaille est 5312483703128064 ce qui provoque une erreur de dépassement de capacité quand on appelle la méthode Left.
Y a-t-il une erreur dans la manière d'utiliser la méthode GetPrivateProfileStringA avec vb?net ? Quelqu'un a-t-il une idée ?

Merci
A voir également:

1 réponse

sroz Messages postés 9 Date d'inscription jeudi 3 mars 2005 Statut Membre Dernière intervention 19 juin 2007
29 mars 2005 à 14:46
classe pour lire un fichier ini :
http://experienz.net/index.php?option=com_content&task=view&id=109&Itemid=42

ça marche très bien
3
Rejoignez-nous