Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Hey jkr how do I extract the command line args using parsecommandline?

Now that I have everything installed how do I extract the command line args? Thanks.
0
zstafa
Asked:
zstafa
  • 4
  • 3
1 Solution
 
jkrCommented:
Well, what arguments would you like to use and for what purpose?
0
 
zstafaAuthor Commented:
I just need to read in an ip address as a character array, an int, and 4 LONGINTs
0
 
jkrCommented:
And in which format should that be? E.g.

prog.exe 127.0.0.1 1234 4567 8901 2345

?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkrCommented:
Oh, and what meaning/variable names should the fields have?
0
 
zstafaAuthor Commented:
Yes that is correct. The names will be

char[100] ip
int channel
LONGINT startd
LONGINT endd
LONGINT startt
LONGINT endt
0
 
jkrCommented:
You could use

bool GetLONGINT(CString& str, LONGINT& rln)
{
   char* pcCnvEnd = NULL;

   rln = strtol(str,&pcCnvEnd,10);

   if (*pcCnvEnd) return false; //incorrect input format

   return true;
}


void CMyWinApp::ParseCommandLine(CCommandLineInfo& rCmdInfo)
{
    for (int i = 0; i < m_commandLineParameters.size(); i++)
    {
        BOOL bFlag = FALSE;
        BOOL bLast = ((i + 1) == m_commandLineParameters.size());
        if (m_commandLineParameters[i].GetAt(0) == '-' || m_commandLineParameters[i].GetAt(0) == '/')
        {
            m_commandLineParameters[i] = m_commandLineParameters[i].Right(m_commandLineParameters[i].GetLength() - 1);
            // remove flag specifier
            bFlag = TRUE;
        }
        rCmdInfo.ParseParam(m_commandLineParameters[i], bFlag, bLast);

            switch(i)

            case 1: strcpy(ip,m_commandLineParameters[i]); break;
            case 2:
            
                  if (!GetLONGINT(&channel) {

                        // error
                  }

                  break;
 
             case 3:
            
                  if (!GetLONGINT(&startdd) {

                        // error
                  }

                  break;

            case 4:
            
                  if (!GetLONGINT(&endd) {

                        // error
                  }

                  break;

            case 5:
            
                  if (!GetLONGINT(&startt) {

                        // error
                  }

                  break;

             case 6:
            
                  if (!GetLONGINT(&endt) {

                        // error
                  }

                  break;


  }
}
0
 
zstafaAuthor Commented:
I'm still having issues populating m_commandLineParameters. Let me know if you want tme to start another thread. Thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now