Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to pass a string to a MFC app through the command line

Status
Not open for further replies.

nytyme

Programmer
Jan 8, 2001
19
US
i want to write an application so that i can pass a string to application using the command line.
MyApp.exe "Hello Wold"

i may be misunderstanding it, but the MFC command line parsing appears to only look at specific flags.
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
ParseCommandLine() calls ParseParam which is expecting these flags: /p, /pt, /dde, /Automation, and /Embedding

how do i use my own stuff?
thanks,
NyTyme
 
In application Class InitInstance Member function:

if( m_lpCmdLine[0] != NULL)
strcpy( ccmd_line_arg, m_lpCmdLine);


You can get the command line switches.

THE CMyApp::m_lpCmdLine member var contains the command line switches.

HTH,
Asher

Shift to the left! Shift to the right! Pop up, push down! Byte! Byte! Byte!"
 
Thank you for the code, I'm sure I will need it later.
However I'm not sure it gives me what I want.

I want the equivalent of argc and argv in a console application or lpCmdLine and nCmdShow in WinApp32.

The method you gave me returns the whole CommandLine string, but its still has the problem of expecting these flags: /p, /pt, /dde, /Automation, and /Embedding
case in point:
from the command line i type "MyApp.exe Hello" and i get
"C:\hello" was not found
from the command line i type "MyApp.exe MyApp.exe Hello" and the application launches... showing me "MyApp.exe Hello".

the application calling MyApp.exe is only going to send "hello" to MyApp.exe. I need to know how to do this. Do I have to change a MFC Function? I thought I read somewhere that I might have to.

Thanks again,
NyTyme
 
ahoodin is right.
write your own ParseCommandLine() and parse through m_lpCmdLine
 
Ah, it took me a bit, but I caught your meaning.
Thanks Ahoodin

if( m_lpCmdLine[0] != NULL)
strcpy( ccmd_line_arg, m_lpCmdLine);

works, but i had to comment out this stuff first:
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

really simple solution, thanks alot :)

have a good one.
NyTyme
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top