Created
September 17, 2017 07:57
-
-
Save SpaceManiac/3c1ee2e2088107838718254545a08304 to your computer and use it in GitHub Desktop.
CommandLineToArgvW differs from argc/argv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D:\projects\Sandbox>"cpp/"a.exe "cpp/"a.exe | |
---- argc and argv think: | |
0: cpp/a.exe | |
1: cpp/a.exe | |
---- GetCommandLineW is: | |
"cpp/"a.exe "cpp/"a.exe | |
---- CommandLineToArgvW thinks: | |
0: cpp/ | |
1: a.exe | |
2: cpp/a.exe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
int main(int argc, char* argv[]) { | |
printf("---- argc and argv think:\n"); | |
for (int i = 0; i < argc; ++i) { | |
printf("%i: %s\n", i, argv[i]); | |
} | |
printf("---- GetCommandLineW is:\n"); | |
printf("%ws\n", GetCommandLineW()); | |
printf("---- CommandLineToArgvW thinks:\n"); | |
LPWSTR *szArglist; | |
int nArgs; | |
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); | |
if (szArglist == NULL) { | |
wprintf(L"CommandLineToArgvW failed\n"); | |
return 0; | |
} | |
for (int i = 0; i < nArgs; i++) { | |
printf("%d: %ws\n", i, szArglist[i]); | |
} | |
LocalFree(szArglist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment