CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Posts
    4,640

    Different behavior using CreateProcess vs. launching directly...

    Hey all,

    This is interesting. I have two MFC based apps, one dialog based, one MDI based. The dialog based app has the ability to launch the MDI app, using CreateProcess:
    Code:
       PROCESS_INFORMATION procInfo;
            STARTUPINFO startInfo;
            memset (&startInfo, 0, sizeof(STARTUPINFO));
            startInfo.cb = sizeof(STARTUPINFO);
            ::CreateProcess(
                NULL,                                               // name of executable module
                commandLine.GetBuffer(commandLine.GetLength()+1),   // command line string
                NULL,                                               // SD
                NULL,                                               // SD
                FALSE,                                              // handle inheritance option
                DETACHED_PROCESS,                                   // creation flags
                NULL,                                               // new environment block
                NULL,                                               // current directory name
                &startInfo,                                               // startup information
                &procInfo                                                // process information
                );
            commandLine.ReleaseBuffer();
    		::CloseHandle(procInfo.hThread);
    		::CloseHandle(procInfo.hProcess);
    Where 'commandLine' is:
    Code:
    "d:\Projects\FR\debugbin\AppName" ""D:\Projects\FR\test\001148940"
    In re-reading the docs, I guess I don't need the "DETACHED_PROCESS" flag, as this is not a console app.

    Anyhow, if I launch the app this way, I get all sorts or weirdness when printing in the second (MDI) app. First, my clients are saying that no matter what, a maximum of 3 pages is printed. Whether they specify a range, or try to print the whole document.

    I just recompiled both apps to use MFC statically (CRT statically, too), and they are now getting an error when printing ("Improper Argument") when printing. I do get an assertion in the CView class:
    Code:
    In CView::DoPreparePrinting:
    ENSURE(pInfo->m_strPageDesc.LoadString(AFX_IDS_PREVIEWPAGEDESC));
    I can reproduce the issues they are seeing; however, I cannot reproduce *any* of this if I run the MDI app standalone!!! Everything works great!

    My guess is that this is some result of the fact that the MDI app is a child process of the dialog app. Is there a trick to doing something like this?

    Thanks!!!

    Viggy

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Different behavior using CreateProcess vs. launching directly...

    Quote Originally Posted by MrViggy View Post
    My guess is that this is some result of the fact that the MDI app is a child process of the dialog app.
    Windows doesn't really have the concept of a child process. I would remove the DETACH_PROCESS flag and set the lpCurrentDirectory to the location where the new exe is located.

  3. #3
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Different behavior using CreateProcess vs. launching directly...

    Hmm, interesting. I bluffed! Well, okay, maybe not exactly. I do see this strange behavior when I run standalone. All I did was change to statically link the MFC and CRT libraries.

    Viggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured