Re: C++ program only works with breakpoint
Ok, my code is now:
const char o[5] = "open";
const char a[83] = "C:\\Program Files\\Adobe\\Adobe Photoshop
CS3\\Plug-Ins\\AnanyaCurves\\AnanyaCurvesW.exe";
string str = ... //for defining args[0] of the Java program
const char *s = str.c_str();
SHELLEXECUTEINFO ei = {0};
ei.cbSize = sizeof(ei);
ei.fMask = SEE_MASK_NOCLOSEPROCESS;
ei.lpVerb = o;
ei.lpFile = a;
ei.lpParameters = s;
ei.nShow = SW_NORMAL;
ei.hInstApp = NULL;
ShellExecuteEx(&ei);
if ( ei.hProcess != NULL )
{
WaitForSingleObject(ei.hProcess, 5*1000);
}
However, WaitForSingleObject just waits 5 seconds.
This helped with my other problem of ShellExecute being slow sometimes. Now
it always only takes a split second. (The reason that it was slow was that
the C++ program and the Java program ran simultaneously.) Thanks a lot!
However, I still have to set a breakpoint when opening my javaFile.dat,
otherwise my javaFile communication does not work.
How can I properly make my C++ program wait until my Java program closes, at
which point the javaFile.dat is opened up?
(As I showed before, saying:
while (file.is_open() == false) file.open("javaFile.dat", ios::binary)
does not work).)
Thanks in advance for your help!
"Igor Tandetnik" wrote:
"Ananya" <Ananya@discussions.microsoft.com> wrote in message
news:272D9E39-B60F-4764-9408-D2094CCFAC5D@microsoft.com
After calling ShellExecute, I have the two lines of code:
ifstream file;
while (file.is_open() == false) file.open("javaFile.dat",
ios::binary);
and then I have the code for reading the file.
I suspect you open the file as soon as Java program creates it, but
before it finishes writing data into it.
Use ShellExecuteEx with SEE_MASK_NOCLOSEPROCESS flag, rather than
ShellExecute. This gives you hProcess handle that you can use with
WaitForSingleObject. This way you know when the process has terminated,
and don't need to rely on polling the file.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925