MFC Command Line Arguments

Hey,

I'm tring to get the command line arguments from my application but it is not returning the correct results. It is only ever returning the first letter and not the whole string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Command Line: test.exe /t /is /a "test"

printf("%i", __wargc);
Returns: 5

printf("%s", __wargv[0]);
Returns: t

printf("%s", __wargv[1]);
Returns: /

printf("%s", __wargv[2]);
Returns: /

printf("%s", __wargv[3]);
Returns: /

printf("%s", __wargv[4]);
Returns: t
Last edited on
printf function only deals with char size (ascii) only characters.
If you are passing a wide (2 byte UNICODE) string then the second byte of each character is 0 (zero) - this will look to the printf function like a very short string (one byte size char followed by terminating NULL).

Example:

letter A = 41 - in ASCII (hex) one byte
letter A = 41 00 - in 2 byte UNICODE -
Topic archived. No new replies allowed.