dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: How to run an executable with a MFC program ?

  1. #1
    Join Date
    May 2001
    Posts
    4

    How to run an executable with a MFC program ?

    Hi there ,

    How can I execute a .exe program with a MFC application . I try with execl() instruction , it compiles perfectly , but wen I run the application , an error occurs . With system("program.exe") instruction , an DOS windows appear and is quite nasty .
    If someoane can send me a simple MFC app or another instruction with that can execute a program into a MFC application .
    Thanks!


  2. #2
    Join Date
    Oct 2000
    Location
    India
    Posts
    489

    Re: How to run an executable with a MFC program ?

    Look at ShellExecute, CreateProcess.
    Do not use System.

    regards
    Prem
    Regards,
    Prem

  3. #3
    Join Date
    May 2001
    Posts
    112

    Re: How to run an executable with a MFC program ?

    Like the other person said, ShellExecute should do it:
    ShellExecute( GetSafeHwnd(), "open", "C:\\mydir\\myProgram.exe", NULL, NULL, 1 );


    or
    // This will reply on the Windows ability to open an XLS file
    ShellExecute( GetSafeHwnd(), "open", "C:\\mydir\\myFile.xls", NULL, NULL, 1 );



    That should get you started.
    For more fun, check MSDN and do a search for ShellExecute...
    ( http://msdn.microsoft.com )

    Rock on,
    RosinCore

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to run an executable with a MFC program ?


    STARTUPINFO siStartupInfo;
    PROCESS_INFORMATION piProcessInfo;

    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    memset(&piProcessInfo, 0, sizeof(piProcessInfo));

    siStartupInfo.cb = sizeof(siStartupInfo);

    if(CreateProcess("c:\\test\\test.exe", // Application name
    " example.txt", // Additional application arguments
    NULL,
    NULL,
    FALSE,
    CREATE_NO_WINDOW | CREATE_DEFAULT_ERROR_MODE,
    NULL,
    NULL,
    &siStartupInfo,
    &piProcessInfo) == FALSE)
    // Could not start application

    // Wait until application has terminated
    WaitForSingleObject(piProcessInfo.hProcess, INFINITE);

    // Close process and thread handles
    ::CloseHandle(piProcessInfo.hThread);
    ::CloseHandle(piProcessInfo.hProcess);




    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds

  5. #5
    Join Date
    May 2000
    Location
    MI - USA
    Posts
    488

    Re: How to run an executable with a MFC program ?

    Use


    WinExec("Program.EXE");




    Good Luck!

    Narayana Murty


    Rate this post if it helped you!


  6. #6
    Join Date
    Oct 2000
    Location
    India
    Posts
    489

    Re: How to run an executable with a MFC program ?

    The foll. is an excerpt from MSDN, on why u should not use 'WinExec'.

    The WinExec function runs the specified application.

    Note This function is provided only for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function.


    regards
    Prem
    Regards,
    Prem

  7. #7
    Join Date
    May 2000
    Location
    MI - USA
    Posts
    488

    Re: How to run an executable with a MFC program ?

    You might be right, if the posted question is exactly looking for the answer of CreateProcess(), but here the question is bit different. so the answer should be WinExec() not CreateProcess() or ShellExecute(). Read the question once again.

    Narayana Murty.


  8. #8
    Join Date
    Oct 2000
    Location
    India
    Posts
    489

    Re: How to run an executable with a MFC program ?

    Q: How can I execute a .exe program with a MFC application.

    The aim is to execute an application, as the Documetation states,
    WinExec should not be used, for all we know it may run in a VDM,
    and also the documentation states a 'security' reason when passing file
    names with spaces.

    As a programmer, u should always look to move forword, not backword.

    regards
    Prem
    Regards,
    Prem

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)