Search This Blog

Tuesday, January 13, 2009

Command line arguments - LPWSTR to char*

if you want to see the command line arguments of you can use the argc and argv parameter , in my program i create a service with ATL (vc++) and the argc / argv are missing .
so to get the arguments in this case i used the next code snippets:

LPWSTR *szArglist;
int nArgs;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
.......
To convert the character from LPWSTR to char* i use the next macro:
W2A - (vice versa A2W) you will have to add in your function the macro
USES_CONVERSION
e.g.
char *pp = W2A(szArglist[1]);
LocalFree(szArglist);// Free memory allocated
Yaniv

No comments: