Hello all,
Inside an XPsp3 CMD.EXE console window :
I've just used 'GetVolumeInformation' function to retrieve a drives volume name and noticed that it looks differently from when I did a "dir" for the same drive.
The "dir" command returns an intended 0xFA (a small vertically-centered
dot), the GetVolumeInformation function returns a 0XB7 (single border left, double border down).
I'm /guessing/ that some kind of characterset translation is performed
by/for the "dir" command. How can I have the same done to (the output of) the GetVolumeInformation function ?
Regards,
Rudy Wieser
The Middle Dot character's Unicode Codepoint is 0xB7 which is the same character code for Windows (ANSI) code page. DIR generates character
code translated to OEM US code page 437, which is 0xFA.
If you switch to code page 1252 in CMD using `chcp 1252` then capture
the DIR output, it'll generate character code 0xB7 instead of 0xFA.
IOW, I'm going to see if I can find something that will either only change the codepage for a single program (emulating what the DIR command seems to
be doing), or perhaps even a codepage translation for just that string. Google/DDG, here I come :-)
IOW, I'm going to see if I can find something that will either only change the codepage for a single program
I use Microsoft AppLocale for that.
IOW, I'm going to see if I can find something that will either only change >> the codepage for a single program
I found and tried SetConsoleOutputCP as well as SetConsoleCP, but neither seems to affect the output I'm writing (to the STD_OUTPUT_HANDLE file).
And both seem to remain after my program terminates. :-|
Just make a unicode application
and write the output by means of WriteConsoleW()
m_OutputRedirected = ( GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))
!= FILE_TYPE_CHAR );
Or just assume redirection if WriteConsole fails ;-)
Just make a unicode application
Thanks, but no. I like ASCII too much to ditch it for a problem like this.
and write the output by means of WriteConsoleW()
The last time I looked that needed a console screen buffer. And while playing with that I had to experience that those do not really work nicely alongside of STD_OUTPUT_HANDLE file output (strange stuff happened).
m_OutputRedirected = ( GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))
!= FILE_TYPE_CHAR );
(Named) Pipes are also character devices ...
I'm currently thinking of trying to use a MultiByteToWideChar, WideCharToMultiByte pair to do the translation. Not elegant, but with (seemingly) the absense of anything else it will have to do. :-\
No, WriteConsoleOutput needs console buffer, WriteConsole just a string buffer.
m_OutputRedirected = ( GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))
!= FILE_TYPE_CHAR );
(Named) Pipes are also character devices ...
Nope, they are FILE_TYPE_PIPE.
W function plus WriteConsoleW plus non-bitmap font plus codepage 65001 (UTF-8) is the only way to avoid character translation losses.
Until you hit a FAT drive with non-ASCII charcters in the volume label
(which is OEM-CP on disk) written under a dfferent OEM-CP than the current one :-)
No, WriteConsoleOutput needs console buffer, WriteConsole just a string
buffer.
I'm afraid MS begs to differ :
https://docs.microsoft.com/en-us/windows/console/writeconsole
"hConsoleOutput [in]
A handle to the console screen buffer."
I'm afraid MS begs to differ :
https://docs.microsoft.com/en-us/windows/console/writeconsole
"hConsoleOutput [in]
A handle to the console screen buffer."
I thought you talk about the buffer with the characters to write...
About the handle:
GetStdHandle(STD_OUTPUT_HANDLE) is the handle to the current console
screen buffer and can be used with WriteConsole and WriteConsoleOutput.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:21:15 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,793 |