Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with wide chars (urgent :( )

problem with wide chars (urgent :( )

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gamitech
    wrote on last edited by
    #1

    I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006

    N J 2 Replies Last reply
    0
    • G gamitech

      I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Use W2A


      Nibu thomas Software Developer

      G 1 Reply Last reply
      0
      • N Nibu babu thomas

        Use W2A


        Nibu thomas Software Developer

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        I get thiese 3 errors : error C2065: '_lpw' : undeclared identifier '_convert' : undeclared dentifier error C2065: '_acp' : undeclared dentifier the headers i included (from what I ve read about w2a) are AtlBase.h, AtlConv.h; I am doing a win 32 aplication not mfc by the way :( how should I not get the 3 errors ? gabby -- modified at 4:43 Wednesday 8th March, 2006

        N 1 Reply Last reply
        0
        • G gamitech

          I get thiese 3 errors : error C2065: '_lpw' : undeclared identifier '_convert' : undeclared dentifier error C2065: '_acp' : undeclared dentifier the headers i included (from what I ve read about w2a) are AtlBase.h, AtlConv.h; I am doing a win 32 aplication not mfc by the way :( how should I not get the 3 errors ? gabby -- modified at 4:43 Wednesday 8th March, 2006

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          When using an ATL string conversion macro, specify the USES_CONVERSION macro at the beginning of your function in order to avoid compiler errors.


          Nibu thomas Software Developer

          1 Reply Last reply
          0
          • G gamitech

            I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            You have the right idea here - if you are going to be looping, you might want to stay away from the ATL conversion macros if you are using VC++ 6.0 - those macros dynamically allocate from the stack and you can quickly blow the stack if looping over a good amount of files.

            euacela wrote:

            WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL);

            If name is a pointer (and it looks like it is), you cannot use sizeof(...) on it to determine the size of what it points to.  Try:

            ULONG ulFNLen = n -> FileNameLength;
            char *pcFileName = new char[ ulFNLen + 1 ];

            //
            // Handle Error If pcFileName Is NULL...
            //
            ::WideCharToMultiByte( CP_THREAD_ACP, WC_SEPCHARS, n -> FileName,
                    ulFNLen, pcFileName, ulFNLen, NULL, NULL );
            pcFileName[ ulFNLen ] = '\0'; // Paranoid Terminate The FileName
            //
            // Use pcFileName...
            //
            delete [] pcFileName;

            Your malloc(...) example is incorrect, because it does not include space for a terminating NUL character.    Peace! -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups