IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual C++ Discussion :

GetPrivateProfileString retourne toujours 0


Sujet :

Visual C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Avril 2002
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 61
    Par défaut GetPrivateProfileString retourne toujours 0
    Bonjour,

    J'ai un problème pour utiliser GetPrivateProfileString afin de récupérer des valeurs dans un fichier INI.

    Voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    TCHAR   inBuf[80];
    int res = GetPrivateProfileString(TEXT("ARCHIVAGE"), TEXT("Repertoire"), TEXT(""), inBuf, sizeof(inBuf), TEXT("Regroupement.INI"));
    _tprintf (TEXT("Key: %s %d \n"), inBuf, res);
    Le fichier INI en question :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    [ARCHIVAGE]
    Repertoire=D:\\Temp
    A l'exécution la variable inBuf est toujours vide et res est toujours égal à 0. Le fichier Regroupement.INI est bien dans le même répertoire que mon executable (créé sous Visual Studio 2010).

    Il y a forcément quelque chose que je ne fait pas correctement mais quoi?

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 487
    Par défaut
    Cf. Doc MSDN http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    lpFileName [in]
    The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.

    ..................

    The system maps most .ini file references to the registry, using the mapping defined under the following registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping

    ..................

    The profile functions use the following steps to locate initialization information:

    Look in the registry for the name of the initialization file under the IniFileMapping key.
    Look for the section name specified by lpAppName. This will be a named value under the key that has the name of the initialization file, or a subkey with this name, or the name will not exist as either a value or subkey.
    If the section name specified by lpAppName is a named value, then that value specifies where in the registry you will find the keys for the section.
    If the section name specified by lpAppName is a subkey, then named values under that subkey specify where in the registry you will find the keys for the section. If the key you are looking for does not exist as a named value, then there will be an unnamed value (shown as <No Name>) that specifies the default location in the registry where you will find the key.
    If the section name specified by lpAppName does not exist as a named value or as a subkey, then there will be an unnamed value (shown as <No Name>) that specifies the default location in the registry where you will find the keys for the section.
    If there is no subkey or entry for the section name, then look for the actual initialization file on the disk and read its contents.
    ...........
    En résumé, n'utilisez plus GetPrivateProfileString, mais la base de registre.

Discussions similaires

  1. [XSLT]fonction contains retourne toujours false
    Par wildmary dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 01/08/2007, 11h22
  2. 1 site, 2urls, on retourne toujours la même url
    Par c4cf6 dans le forum Apache
    Réponses: 1
    Dernier message: 29/06/2007, 17h02
  3. fonction retournant toujours 0.000 ?
    Par _SamSoft_ dans le forum C
    Réponses: 49
    Dernier message: 22/02/2007, 20h52
  4. [sockets] gethostbyname retourne toujours la même chose
    Par Strab dans le forum Développement
    Réponses: 3
    Dernier message: 15/09/2006, 10h24
  5. Réponses: 2
    Dernier message: 30/03/2006, 16h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo