qocarlos
asked on
Help using ShellExecuteEx
I have developed two applications (A, B). What I wanted to do is to run B from A. I used the following code, in the application A, to execute B:
SHELLEXECUTEINFO aShellExecStruct;
aShellExecStruct.cbSize = sizeof(SHELLEXECUTEINFO);
aShellExecStruct.fMask = SEE_MASK_NOCLOSEPROCESS;
aShellExecStruct.hwnd = ::GetDesktopWindow();
aShellExecStruct.lpVerb = "open";
aShellExecStruct.lpFile ="B.exe";
aShellExecStruct.lpParamet ers = lpszPathName;
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);
}
}
else
{
AfxMessageBox("cannot run B");
}
The problem I have now is that, after closing B, it should return two variables so I could use them in A. I can't figure out how to do this.
Any help will be greatly appreciated,
regards,
Carlos
SHELLEXECUTEINFO aShellExecStruct;
aShellExecStruct.cbSize = sizeof(SHELLEXECUTEINFO);
aShellExecStruct.fMask = SEE_MASK_NOCLOSEPROCESS;
aShellExecStruct.hwnd = ::GetDesktopWindow();
aShellExecStruct.lpVerb = "open";
aShellExecStruct.lpFile ="B.exe";
aShellExecStruct.lpParamet
aShellExecStruct.lpDirecto
aShellExecStruct.nShow = SW_SHOWNORMAL;
BOOL aResult = ::ShellExecuteEx(&aShellEx
if (aResult)
{
HANDLE aProcHandle = aShellExecStruct.hProcess;
if (aProcHandle)
{
::WaitForSingleObject(aPro
}
}
else
{
AfxMessageBox("cannot run B");
}
The problem I have now is that, after closing B, it should return two variables so I could use them in A. I can't figure out how to do this.
Any help will be greatly appreciated,
regards,
Carlos
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's not necessary to 'DuplicateHandle()' - well, I also thought of using the exit code, but as qocarlos wants to pass two variables, it doesn't seem to be an option (hmm, and we still don't know what type of data these variables contain...)
ASKER
Hi jkr,
Thanks for your answer!
I can write the variables from B (either to the registry or to a file) but I need to do it only in the case that B has be executed from A. If B was executed like a stand-alone application,
I don't want to write this file.
How can I know this? and also, which is the best place in B to save the variables (they belong to the document derived class)?
Carlos
Thanks for your answer!
I can write the variables from B (either to the registry or to a file) but I need to do it only in the case that B has be executed from A. If B was executed like a stand-alone application,
I don't want to write this file.
How can I know this? and also, which is the best place in B to save the variables (they belong to the document derived class)?
Carlos
ASKER
About the GetExitCodeProcess(...) function:
The variables I need to get are in double floating format (for instance, numbers 123.732 and -89.12)
I think I can't do this with GetExitCodeProcess or am I wrong?
Carlos
The variables I need to get are in double floating format (for instance, numbers 123.732 and -89.12)
I think I can't do this with GetExitCodeProcess or am I wrong?
Carlos
oops sorry - I thought he wanted to get the return code (1 value) not two seperate values :)
yup - registry or file - or you could send a message to the other app with the data in
yup - registry or file - or you could send a message to the other app with the data in
>>If B was executed like a stand-alone
>>application, I don't want to write
>>this file.
You could do this by passing an additional argument on the command line, e.g.
"b.exe /saveresults"
and check it from within b.exe by using
if ( strstr ( GetCommandLine(), "/saveresults"))
{
// ...
}
I think the best place to store them is either
HKLM\Software\MyCompany\b
or
HKCU\Software\MyCompany\b
The problem with using a file is that both apps have to agree on a location where to store/look for it...
>>application, I don't want to write
>>this file.
You could do this by passing an additional argument on the command line, e.g.
"b.exe /saveresults"
and check it from within b.exe by using
if ( strstr ( GetCommandLine(), "/saveresults"))
{
// ...
}
I think the best place to store them is either
HKLM\Software\MyCompany\b
or
HKCU\Software\MyCompany\b
The problem with using a file is that both apps have to agree on a location where to store/look for it...
ASKER
Thanks!
some pseudo code (i.e. I've not tested this)
if (aProcHandle)
{
HANDLE hDupProcess;
::WaitForSingleObject(aPro
DWORD dwExitCode;
::GetExitCodeProcess(aProc
}
- you may have to dupicate the process handle before WaitForSingleObject(...)
some more pseudo code
if (aProcHandle)
{
HANDLE hDupProcess;
::DuplicateHandle(...,aPro
::WaitForSingleObject(aPro
DWORD dwExitCode;
::GetExitCodeProcess(hDupP
}