Solved

CreateProcess / Command Line Parsing MFC SDI

Posted on 2004-04-02
3
997 Views
Last Modified: 2013-11-20
Want to use CreateProcess to launch another MFC SDI application the First Parameter and passing a file path in the second parameter for the launched program to load.  Making the call as follows:

PROCESS_INFORMATION procInfo;
      BOOL processStarted;
      memset(&suInfo, 0, sizeof(suInfo));
      suInfo.cb = sizeof(suInfo);
      // Kick off the Next Program
      processStarted =       
      CreateProcess(
            "C:\\Program Files\\BuildCustomCatalog\\Chass_Header_New\\Chass_Header_New.exe",
            "C:\\CCBuild\\Commands_New\\9778_W_1_4B974338.txt",
            NULL,                              // process security attributes
            NULL,                              // thread security attributes
            FALSE,                              // handle inheritance flag
            NORMAL_PRIORITY_CLASS,                                      // handle inheritance flag
            NULL,                              // pointer to new environment block
            NULL,                              // pointer to current directory name
            &suInfo,                                        // pointer to STARTUPINFO
            &procInfo);                        // pointer to PROCESS_INFORMATION
}

The launched program chokes on this call.  If I execute the CreateProcess call using NULL for parameter 2 (Command Line Argument i.e. pass no command line argument), the launched program has no problem.  The launched program seems to choke at the "if (!ProcessShellCommand(cmdInfo)) return FALSE;" call in the CWinApp InitInstance() function when a file path is included in the command line;

Any ideas would be appreciated.

Thanks,

Julian
0
Comment
Question by:JulianPugh
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10742386
1) Try to run this program (Chass_Header_New.exe) from command prompt with the same parameter - what happens?
2) Both program name and parameter may be in the second CreateProcess parameter:

CreateProcess(
         NULL,
         "C:\\Program Files\\BuildCustomCatalog\\Chass_Header_New\\Chass_Header_New.exe  C:\\CCBuild\\Commands_New\\9778_W_1_4B974338.txt",
         ...


0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 10742552
Does the same thing happen when you specify the command line in your project settings and run the Chass_Header_New.exe from within the developer's studio?

When you say the program chokes what do you mean? Throws an exception? Asserts? Hangs forever?

You are calling ProcessShellCommand() after the following commands:

  // Parse command line for standard shell commands, DDE, file open
  CCommandLineInfo cmdInfo;
  ParseCommandLine(cmdInfo);

And after your document has been setup.

The CWinApp::ProcessShellCommand() routine in APPUI2.CPP has a switch and the following is executed when you pass your parameters:

  case CCommandLineInfo::FileOpen:
    if (!OpenDocumentFile(rCmdInfo.m_strFileName))
      bResult = FALSE;
    break;

Can your document's OpenDocumentFile handle the file name?

Good Luck,
Steve
0
 

Author Comment

by:JulianPugh
ID: 10742560
Alex,

Passed the exe file path and file to load in the second CreateProcess parameter, as you suggested, and everything works perfectly fine.  I really appreciate your help.

thanks,

Julian
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 123
windows 10 how make picture as desktop background 2 58
tripleUp challenge 7 74
Problem to event 3 78
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now