Click here to Skip to main content
       

C / C++ / MFC

 
QuestionRe: get the txt of wordArt with VBA PinmvpCPallini5-Aug-12 21:03 
AnswerRe: get the txt of wordArt with VBA PinmemberBianChengNan5-Aug-12 21:17 
QuestionMFC Ribbon Status Bar in VS2010 PinmemberRishav Prabhakar5-Aug-12 19:22 
QuestionCalling main from within Windows application PinmemberPierreBokma5-Aug-12 3:34 
AnswerRe: Calling main from within Windows application PinmvpRichard MacCutchan5-Aug-12 6:51 
AnswerRe: Calling main from within Windows application Pinmemberjschell5-Aug-12 7:53 
AnswerRe: Calling main from within Windows application Pinmemberpasztorpisti5-Aug-12 15:08 
AnswerRe: Calling main from within Windows application PinmemberTopCoder235-Aug-12 18:37 
Try this.
 

 
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
typedef TCHAR tchar;
typedef std::basic_string<tchar> tstring;
typedef std::basic_stringstream<tchar> tstringstream;
typedef std::vector<tstring> arg_vector;
 
bool filter(char c)
{
    return (c == '\"');
}
 
arg_vector cmdline_to_argv(tstring const & cmdline)
{
    arg_vector args;
 
    if (cmdline.empty())
        return args;
 
    bool together = false;
    bool only_spaces = true;
    tstring::size_type laststart = 0;
 
    for (tstring::size_type n = 0; n < cmdline.length(); ++n)
    {
        if (cmdline[n] == '\"')
        {
            together = !together;
        }
 
        bool space = !!isspace(cmdline[n]);
 
        if (space && !together)
        {
            if (!only_spaces)
            {
                tstring arg = cmdline.substr(laststart, n - laststart + 1);
                arg.resize(std::remove_if(arg.begin(), arg.end(), &filter) - arg.begin());
                args.push_back(arg);
            }
            laststart = n + 1;
        }
 
        if (space)
            only_spaces = true;
        else
            only_spaces = false;
    }
 
    if (!only_spaces)
    {
        tstring arg = cmdline.substr(laststart, cmdline.length() - laststart + 1);
        arg.resize(std::remove_if(arg.begin(), arg.end(), &filter) - arg.begin());
        args.push_back(arg);
    }
 
    return args;
}
 

int main(arg_vector const & args)
{
    tstringstream strm;
    strm << args.size() << " arguments!\n";
    for (arg_vector::size_type n = 0; n < args.size(); ++n)
        strm << "Argument #" << (n + 1) << ": " << args[n] << "\n";
    MessageBox(NULL, strm.str().c_str(), TEXT("Command Line Test"), MB_OK | MB_ICONINFORMATION);
    return 0;
}
 
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int show)
{
    return main(cmdline_to_argv(GetCommandLine()));
}
 

QuestionBEX runtime error! PinmemberLe@rner2-Aug-12 18:54 
AnswerRe: BEX runtime error! PinmemberPeter_in_27802-Aug-12 19:04 
AnswerRe: BEX runtime error! PinmvpRichard MacCutchan2-Aug-12 21:21 
AnswerRe: BEX runtime error! Pinmemberenhzflep2-Aug-12 23:41 
AnswerRe: BEX runtime error! PinmemberTopCoder233-Aug-12 0:34 
AnswerRe: BEX runtime error! PinmemberWes Aday3-Aug-12 6:54 
Questioncalling a user32.lib method in c++ application gives Linker error PinmemberVirendra_ec102-Aug-12 2:31 
AnswerRe: calling a user32.lib method in c++ application gives Linker error PinmemberMass Nerder2-Aug-12 3:27 
Questionwait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberVirendra_ec102-Aug-12 2:23 
AnswerRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 Pinmemberpasztorpisti2-Aug-12 3:58 
AnswerRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 Pingroup_AnsHUMAN_ 2-Aug-12 3:59 
GeneralRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberStephen Hewitt3-Aug-12 6:34 
GeneralRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberVirendra_ec1012-Aug-12 20:37 
QuestionRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberDavidCrow2-Aug-12 6:55 
AnswerRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberVirendra_ec1012-Aug-12 20:39 
AnswerRe: wait for more than 5 seconds on a custom combobox dropdown list control causes win32 C++ application hangs in Windows7 PinmemberStephen Hewitt3-Aug-12 6:36 
QuestionTab control Pinmemberekinnh1-Aug-12 15:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 24 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid