Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to launch an application

Posted on 2000-03-31
6
Medium Priority
?
190 Views
Last Modified: 2013-11-20
I need to execute from my application another program (not Notepad!) and this program must open a txt file.
I tried the following:

void Launch()
{
SHELLEXECUTEINFO aShellExecStruct;
      aShellExecStruct.cbSize = sizeof(SHELLEXECUTEINFO);
      aShellExecStruct.fMask = SEE_MASK_NOCLOSEPROCESS;
      aShellExecStruct.hwnd = ::GetDesktopWindow();
      aShellExecStruct.lpVerb = "open";
      aShellExecStruct.lpFile ="application.exe";
      aShellExecStruct.lpParameters = NULL;
      aShellExecStruct.lpDirectory = "c:\\temp";
      aShellExecStruct.nShow = SW_SHOWNORMAL;
      
      
      BOOL aResult = ::ShellExecuteEx(&aShellExecStruct);      
      if (aResult)
      {
            HANDLE aProcHandle = aShellExecStruct.hProcess;
            if (aProcHandle)
            {
                  ::WaitForSingleObject(aProcHandle, INFINITE);
                  AfxMessageBox("application is done.");
            }
      }
      else
      {
            AfxMessageBox("Could not start the application");
      }
}

This code launchs the application correcly but I don't know how to open a document in this application.

Any idea?

Thanks
0
Comment
Question by:qocarlos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 2673461
aShellExecStruct.lpParameters = "document_File_name";

most applications has the ability to open document  by specifying it in their command line

try this

0
 
LVL 3

Author Comment

by:qocarlos
ID: 2673808
Thanks,
I've also written the application I must execute. The problem is that in this application there is the line
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing

in order to keep the application from creating a blank document at startup.

For this reason, when I specify the file in the command line, nothing is opened.
How can I solve this problem?
0
 
LVL 8

Expert Comment

by:gelbert
ID: 2674271
There are two options:

1. Change your application that before you reset command line(cmdInfo.m_nShellCommand) you save command line in some other variable. This way you would have name of a docunent to open and avoid creating blank document

2. Make COM Outproc server out of your application. Then after creation call interface method to specify name of document to open
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 1

Expert Comment

by:tvanceplus
ID: 2674353
try using the

WinExec(LPCSTR filename,NULL)

function. It is easier to use than the shell commands


Good Luck!
0
 
LVL 5

Accepted Solution

by:
vachooho earned 400 total points
ID: 2674803
if(
cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)  cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

will not open new empty document but will allow to open file.


0
 
LVL 3

Author Comment

by:qocarlos
ID: 2675797
Thanks!

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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