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

 C Discussion :

Afficher à l'écran des chaînes de type WCHAR


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 140
    Par défaut Afficher à l'écran des chaînes de type WCHAR
    Bonsoir,

    J'aimerais un équivalent de printf %s pour afficher des chaînes unicode UFT-16 de type WCHAR. J'ai essayé printf %S, ça marche déjà mieux, mais dès que ça rencontre un caractère null, ça stoppe la lecture.

    Évidemment, j'arrive à les lire en ayant recours à une boucle, mais si je dois afficher des milliers de lignes, la durée d'exécution s'accroît très rapidement.

    Merci.

  2. #2
    Expert confirmé
    Avatar de Melem
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2006
    Messages
    3 656
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 3 656
    Par défaut
    Bah, le caractère NUL est le terminateur des chaînes de caractères en C. C'est plutôt normal. printf("%S\n", wstring) est équivalent à wprintf(L"%s\n", wstring). A part le fait que printf("%S\n", wstring) n'est pas standard ...

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 140
    Par défaut
    Salut Melem,

    Merci pour ta réponse.

    J'ai une autre question : comment wprintf récupère la taille du buffer de type WCHAR ? Car lorsque je l'utilise, une fois sur 10 environ, il y a débordement du buffer, et donc erreur de segmentation et le programme plante.

    Si le lis caractère par caractère, aucune erreur, mais c'est beaucoup plus lent.

    Tu as une idée ?

    Merci.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 140
    Par défaut
    Je vais illustrer.

    Voici ce que j'obtiens en utilisant wprintf(L"%s\n") sur "HKLM\Machine\Software\Microsoft\Windows\CurrentVersion\Run" :

    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\IMAIL
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\MAPI
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\MSFS
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a\ !!! 999624
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a\ !!! 999624\
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\b
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c\aaaaaaaaaaaaaaaaaaaa
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c\aaaaaaaaaaaaaaaaaaaa\111
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\d
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\djqDHJJQDHJQHJD
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\dvffdfd
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5Ä55
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5\---------------------------------------------------------
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5\---------------------------------------------------------\2Ä55
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\pppppp
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\pppppp\zzzzzz
    J'ai des caractères intempestifs qui se rajoutent de temps à autre et ça fait planter le programme.

    Si j'utilise une boucle du genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      for (a = 0; a < (FullNtPath.Length)/sizeof(WCHAR); a++)
        printf("%c", FullNtPath.Buffer[a]);
      printf("\n");
    J'obtiens :

    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\IMAIL
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\MAPI
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\OptionalComponents\MSFS
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a\ !!! 999624
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a\ !!! 999624\
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\b
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c\aaaaaaaaaaaaaaaaaaaa
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c\aaaaaaaaaaaaaaaaaaaa\111
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\d
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\djqDHJJQDHJQHJD
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\dvffdfd
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5\---------------------------------------------------------
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e\1\2\3\4\5\---------------------------------------------------------\2
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\pppppp
    \Registry\Machine\Software\Microsoft\Windows\CurrentVersion\Run\TEST\pppppp\zzzzzz
    Tu as une idée ?

    Si je résume : j'arrive à afficher les informations requises, mais actuellement je suis obligé d'utiliser une boucle pour lire caractère par caractère et ce n'est pas du tout convenable en terme de durée. Pour 30 clés ça va, pour 100.000 c'est autre chose.

    Merci par avance.

  5. #5
    Expert confirmé
    Avatar de Melem
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2006
    Messages
    3 656
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 3 656
    Par défaut
    Poste le code complet.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    140
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 140
    Par défaut
    Le code complet ? Il y aurait beaucoup à mettre puisque ça fait intervenir 5 à 6 fonctions en plus du main...

    En fait, wprintf lit les chaines jusqu'au caractère null, c'est bien ça ?

    Car mes chaînes WCHAR que je manipule ne sont pas "null terminated", elles sont toutes définies de la manière suivante :

    typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR Buffer;
    } UNICODE_STRING;
    Pourquoi elles ne sont pas "null terminated" ? Parce que j'ai besoin de rechercher les clés qui ne peuvent pas être lues via reg.exe ou regedit, donc obligé de ne pas s'arrêter au caractère null.

    Et je pense que c'est le souci ici avec wprintf. Je me trompe ?

    Cela dit, en y réfléchissant, le délai avec la boucle est raisonnable, puisque je distingue le cas de figure listage de clé avec caractère null et listage de clé sans caractère null. Dans le premier cas je boucle, dans le second j'utilise wprintf.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 27/05/2015, 11h13
  2. Réponses: 0
    Dernier message: 30/12/2011, 14h57
  3. [Débutant] Programme qui affiche des chaînes de caractère
    Par funy16 dans le forum Débuter avec Java
    Réponses: 8
    Dernier message: 04/11/2009, 09h44
  4. [TP] Afficher des chaînes contenues dans un tableau
    Par mah00 dans le forum Turbo Pascal
    Réponses: 8
    Dernier message: 20/05/2007, 09h15
  5. Afficher/cacher des éléments de type select en fonction d'autres
    Par GLDavid dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 05/04/2006, 10h06

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