Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI MFC VC++ CLI
Hi all
i am stucked in a problem.i want to pass some variables values from a program to a mfc dialog based   exe...the number of arguments that i want to pass is 3.
is there any way by which i can pass these three arguments into the mfc based exe..
really i am in a urgent need...
Posted 19-Jan-12 23:09pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

simply us the getcommandline() function this fucntion stakes the argumnets from the comandline,and acc u could use them.
  Permalink  
v2
Comments
Marcus Kramer at 24-Jan-12 9:40am
   
Thanks for sharing the answer you found. I wish more people would do this once they have found a solution not provided by a member here already. +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Derive a class from CCommandLineInfo and add your implementation of the virtual member function ParseParam() to process your application specific parameters. The derived class should contain member variables to store your parameters.
 
Process the command line in InitInstance() of your application using your command line info class:
BOOL CMyApp::InitInstance()
{
//...
    // Parse command line
    CMyCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    // Process your command line options here using the member vars
    //  of cmdInfo
//...
    // Optional default handling:
    // Dispatch commands specified on the command line.  Will return FALSE if
    // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
    if (!ProcessShellCommand(cmdInfo))
        return FALSE;
//...
    return TRUE;
}
 
UPDATE: A very simple CCommandLineInfo derived class.
class CMyCmdLineInfo : public CCommandLineInfo
{
public:
    CMyCmdLineInfo(void);
    virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
    bool m_bBoolParam;
    bool m_bHelp;
    CString m_strFileParam;
};
 
CMyCmdLineInfo::CMyCmdLineInfo()
{
    m_bBoolParam = m_bHelpParam = false;
}
 
void CMyCmdLineInfo::ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
{
    bool bHandled = false;
    TCHAR lpszParse = pszParam;
    if (bFlag)
    {
        switch (*lpszParse)
        {
        case _T('b') :
        case _T('B') : m_bBoolParam = bHandled = true; break;
        case _T('h') :
        case _T('H') :
        case _T('?') : m_bHelp = bHandled = true; break;
        case _T('f') : 
            ++lpszParse;
            if (*lpszParse == _T('='))
                ++lpszParse;
            m_strFileParam = lpszParse;
            bHandled = true;
            break;
        }
    }
    // If the last parameter has no flag, it is treated as the file name to be
    //  opened and the string is stored in the m_strFileName member.
    if (!bHandled)
        CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
}
  Permalink  
v3
Comments
vaibhavbvp at 20-Jan-12 4:53am
   
hello are you having any sample code for that..i have tried to inherit class from the CCommandLineInfo ,bt i could not get the desired result...it is showing error in CCommandLineInfo class..
Jochen Arndt at 20-Jan-12 5:17am
   
I have updated the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 385
1 Sergey Alexandrovich Kryukov 329
2 CPallini 270
3 DamithSL 214
4 Maciej Los 192
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100