Click here to Skip to main content
13,042,819 members (76,222 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 22:09pm
Rate this: bad
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.
Marcus Kramer 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
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;
    // 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
    virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
    bool m_bBoolParam;
    bool m_bHelp;
    CString m_strFileParam;
    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') : 
            if (*lpszParse == _T('='))
            m_strFileParam = lpszParse;
            bHandled = true;
    // 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);
vaibhavbvp 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 is showing error in CCommandLineInfo class..
Jochen Arndt 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Jan 2012
Copyright © CodeProject, 1999-2017
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