• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Easy parsing of the command line (UNICODE)

Started by Patrice Terrier, February 07, 2014, 11:08:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

To parse a UNICODE command line, i would recommend the use of the built-in CommandLineToArgW API

See the MSDN documentation here.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

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()));
}


Patrice Terrier

#2
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 Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
    Ok I get it.
Your msdn link was of  console app and with a console app I do it as shown.

James