Article View: borland.public.cppbuilder.nativeapi
Article #11904calling dos program
From: Fraser Ross
Date: Sat, 10 Jan 2004 17:39
Date: Sat, 10 Jan 2004 17:39
60 lines
2549 bytes
2549 bytes
Sometimes when I run the dos program it appears to terminate before it is
finished. It should overwrite a few bytes at the start of the output file
it writes before finishing. I did not make the dos program.
I think the problem is to do with this:
DWORD WaitForSingleObject(
HANDLE hHandle, // handle of object to wait for
DWORD dwMilliseconds // time-out interval in milliseconds
);
Parameters
hHandle
Identifies the object. For a list of the object types whose handles can be
specified, see the following Remarks section.
Windows NT: The handle must have SYNCHRONIZE access. For more information,
see Access Masks and Access Rights.
bool RunDosApp(String const parameter) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
std::memset(&pi, 0, sizeof(pi));
std::memset(&si, 0, sizeof(si));
si.cb=sizeof(si);
String command_line("csw.exe \"");
command_line=command_line+parameter+'\"';
// Run the DOS executable with CreateProcess.
int res=CreateProcess(NULL, command_line.c_str(), 0, 0, false,
CREATE_NEW_CONSOLE, 0, 0, &si, &pi);
if (!res) {
// Error...
res=GetLastError();
}
else {
// If we get here, CreateProcess succeeded in starting the DOS app.
res=WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
// Error?
if (res==WAIT_FAILED)
res=GetLastError();
else // All OK, return true.
return true;
}
if (res)
// Something went awry so let the user know.
ShowMessage("Error code is "+(res+'0'));
// Won't get here unless something went wrong.
return false;
}
Fraser.
Technical Details
Message-ID:
<400038d3@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,cd433fcf47e8f03b,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-10 10:09:40 PST From: "Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> Newsgroups: borland.public.cppbuilder.nativeapi Subject: calling dos program Date: Sat, 10 Jan 2004 17:39:34 -0000 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 81.7.54.42 Message-ID: <400038d3@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073756371 81.7.54.42 (10 Jan 2004 09:39:31 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail