qocarlos
asked on
How to launch an application
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.lpParamet ers = NULL;
aShellExecStruct.lpDirecto ry = "c:\\temp";
aShellExecStruct.nShow = SW_SHOWNORMAL;
BOOL aResult = ::ShellExecuteEx(&aShellEx ecStruct);
if (aResult)
{
HANDLE aProcHandle = aShellExecStruct.hProcess;
if (aProcHandle)
{
::WaitForSingleObject(aPro cHandle, 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
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.lpParamet
aShellExecStruct.lpDirecto
aShellExecStruct.nShow = SW_SHOWNORMAL;
BOOL aResult = ::ShellExecuteEx(&aShellEx
if (aResult)
{
HANDLE aProcHandle = aShellExecStruct.hProcess;
if (aProcHandle)
{
::WaitForSingleObject(aPro
AfxMessageBox("application
}
}
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
ASKER
Thanks,
I've also written the application I must execute. The problem is that in this application there is the line
cmdInfo.m_nShellCommand=CC ommandLine Info::File Nothing
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?
I've also written the application I must execute. The problem is that in this application there is the line
cmdInfo.m_nShellCommand=CC
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?
There are two options:
1. Change your application that before you reset command line(cmdInfo.m_nShellComma nd) 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
1. Change your application that before you reset command line(cmdInfo.m_nShellComma
2. Make COM Outproc server out of your application. Then after creation call interface method to specify name of document to open
try using the
WinExec(LPCSTR filename,NULL)
function. It is easier to use than the shell commands
Good Luck!
WinExec(LPCSTR filename,NULL)
function. It is easier to use than the shell commands
Good Luck!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
most applications has the ability to open document by specifying it in their command line
try this