[Webinar] Streamline your web hosting managementRegister Today

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

jkr: problems populating vector

I'm still having problems bringing in the arguments and I'm running out of time. I understand what those functions do and it seems like I am using them properly but m_commandLineParameters.size() never gets bigger than zero. Is this correct in initinstance()

CVID_PlaybackDlg dlg;

CCommandLineInfo cmdInfo;
dlg.ParseCommandLine(cmdInfo);
0
zstafa
Asked:
zstafa
  • 6
  • 4
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
You will have a faster response if you post your question to all experts detailing more your problem.
0
 
zstafaAuthor Commented:
ok I have an mfc program and I'm trying to have it read in command line args at startup. jkr helped me with this function

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;


  }
}

But I am still having problems getting anything to read in.
0
 
Jaime OlivaresSoftware ArchitectCommented:
Are you overriding the ParseCommandLine() method? I think it is not the best approach.

Recommended way (by MSDN) is to derive a class from CCommandLineInfo class, and override the virtual ParseParams() method.

So, what you can do is this:
1) Create a clean app (forgot to override ParseCommandLine)
2) Derive a new class at the beginning of your MyWinApp.cpp file:

class CMyCommandParser : public CCommandLineInfo
{
public:
     virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast) {
          ::AfxMessageBox(pszParam);  // you can process your parameter here
     };
};

3) Then, inside InitInstance replace this:
     CCommandLineInfo cmdInfo;
with this:
     CMyCommandParser cmdInfo;

Now you are in control of command line parsing process.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
zstafaAuthor Commented:
When I did that it tells me CMyCommandParser is an undeclared identifier.
0
 
Jaime OlivaresSoftware ArchitectCommented:
You are missing something, will explain a bit slower:

MyWinApp.cpp   (I suposse this is your main program file)
-----------------

#include "stdafx.h"
// more includes here

class CMyCommandParser : public CCommandLineInfo
{
public:
     virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast) {
          ::AfxMessageBox(pszParam);  // you can process your parameter here
     };
};

/////////////////////////////////////////////////////////////////////////////
// MESSAGEMAP GOES HERE
/////////////////////////////////////////////////////////////////////////////

CMyWinApp::CMyWinApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMyWinAppobject
CMyWinApptheApp;

CMyWinApp::InitInstance()
{
     // Some code here
     CMyCommandParser cmdInfo;    // <--- This is the line you have to change (was: CCommandLineInfo cmdInfo;)
     ParseCommandLine(cmdInfo);
     // etcetera
}

Your error message is very strange, because, as you can see, CMyCommandParser is declared on the same file where is used.
0
 
zstafaAuthor Commented:
I'm new at this stuff. How do I get these values into their variables instead of the afxmessagebox?
0
 
Jaime OlivaresSoftware ArchitectCommented:
Well, that depends on your specific needs, please post your desired command line syntax
0
 
zstafaAuthor Commented:
VID_Playback.exe 192.168.1.167 34 252525 52255 7876878 254545453

char[100] ip
int channel
LONGINT startd
LONGINT endd
LONGINT startt
LONGINT endt

Thanks a lot.
0
 
Jaime OlivaresSoftware ArchitectCommented:
Assuming all those variables will be CMyWinApp members:

class CMyCommandParser : public CCommandLineInfo
{
      int index;

public:
     CMyCommandParser() {
          CCommandLineInfo();
          index=0; // initializes an index to alow make a positional analysis
    };  
 
     virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast) {
          switch (index) {
      case 0:
             strcpy(theApp.ip, pszParam); break;
       case 1:
             theApp.channel = atoi(pszParam); break;
       case 2:
             theApp.startd = atoi(pszParam); break;
      case 3:
             theApp.endd = atoi(pszParam); break;
      case 4:
             theApp.startt = atoi(pszParam); break;
      case 5:
                   theApp.endt = atoi(pszParam); break;
          }
          index++;
     };
};
0
 
Jaime OlivaresSoftware ArchitectCommented:
Forgot to mention, this time you will have to move all this class declaration AFTER this line:

/////////////////////////////////////////////////////////////////////////////
// The one and only CMyWinAppobject
CMyWinApptheApp;

Just before OnInitInstance() implementation.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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