troubleshooting Question

Strange character mapping when running in a cmd shell

Avatar of wayside
wayside asked on
Fonts TypographyC++
10 Comments2 Solutions679 ViewsLast Modified:
I recently ran into a strange problem.

We had send an example of a command line invocation of our software to a customer, who cut and pasted it into a cmd shell (Windows XP). Sadly, it didn't work. The command line looked pretty normal, something like

prog.exe -opt1 -opt2 arg3 -opt3 arg3 etc.

The problem turned out to be that somewhere along the line between us and the customer, one of the dashes got converted from a regular ascii dash (0x2D) to an extended ascii dash (0x96). When the command line was pasted into the cmd shell, what the program got in the argv string was 8211 (0x2013). This completely messed up the string-handling functions and nothing worked of course.

The program is unicode, the main function declaration looks like

int wmain(int argc, wchar_t* argv[])

All string manipulations are done using the unicode versions of the functions.

So the question is:

Why/how did the extended dash character get converted from 0x96 to 0x2013, instead of 0x0096 like the regular ascii characters?

How do I map back from 0x2013 to 0x002D (or even 0x0096)? Obviously, I can run every extended ascii character through the command line, see what winds up in the strings, and build a big case statement to convert back to ascii, but I'm looking for something more algorithmic in nature.

OK, that's 2 questions. :)

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros