To parse a UNICODE command line, i would recommend the use of the built-in CommandLineToArgW API
See the MSDN documentation here. (http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx)
...
Patrice,
Where would one use this?
I tested first just from the command line and then with another app shelling to it.
This is one of the few instances where I use globals. It makes calling the API functions unecessary.
James
test02
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <iostream>
#include <sstream>
#include <tchar.h>
using namespace std;
// *************************************************
// User Global Variables
// *************************************************
static _TCHAR* *g_argv;
static int g_argc;
// *************************************************
// Runtime Functions
// *************************************************
void Pause(void)
{
_tsystem(_T("pause"));
}
// ************************************
// User Subs and Functions
// ************************************
void TestIt ()
{
int i = {0};
for(i = 1; i <= g_argc; i += 1)
{
wcout << g_argv[i - 1] << endl;
}
}
int _tmain (int argc, _TCHAR** argv)
{
g_argc = argc;
g_argv = argv;
TestIt();
Pause();
}
test02test
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <iostream>
#include <sstream>
#include <tchar.h>
using namespace std;
// *************************************************
// User Global Variables
// *************************************************
static _TCHAR* *g_argv;
static int g_argc;
int _tmain (int argc, _TCHAR** argv)
{
g_argc = argc;
g_argv = argv;
wstring ws;
ws = _T("test02.exe one two three");
_tsystem((ws.c_str()));
}
Then what if you need the extra parameters provided by WinMain,
aka: hInstance, hPrevInstance, lpCmdLine, nCmdShow.
I shall show the use of CommandLineToArgvW in context in the next BB64 build.
And also how to browse folders recursively searching for audio files, based on the parsing of the command line.
...
Patrice,
Ok I get it.
Your msdn link was of console app and with a console app I do it as shown.
James