Article View: borland.public.cppbuilder.nativeapi
Article #9936Re: Controlling another application
From: Remy Lebeau (TeamB)
Date: Mon, 31 May 2004 21:59
Date: Mon, 31 May 2004 21:59
49 lines
2436 bytes
2436 bytes
"Daniele Borini" <borini@infinito.it> wrote in message
news:40bb1e04@newsgroups.borland.com...
> this is my code:
Use this code instead:
{
HANDLE hStdInRead = NULL;
HANDLE hStdInWrite = NULL;
HANDLE hStdOutRead = NULL;
HANDLE hStdOutWrite = NULL;
if( CreatePipe(&hStdInRead, &hStdInWrite, NULL, 10000) )
{
if( CreatePipe(&hStdOutRead, &hStdOutWrite, NULL, 10000) )
{
STARTUPINFO sInfo = {0};
PROCESSINFO pInfo = {0};
sInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
sInfo.wShowWindow = SW_NORMAL;
sInfo.hStdInput = hStdInRead;
sInfo.hStdOutput = hStdOutWrite;
sInfo.hStdError = hStdOutWrite;
if( CreateProcess(NULL, "cmd.exe", NULL, NULL, TRUE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &sInfo, &pInfo) )
{
WriteFile(hStdInWrite, dir *.*\n, 8, &i, NULL);
DWORD i = 0;
char str_out[10000] = {0};
ReadFile(hStdOutRead, str_out, sizeof(str_out), &i,
NULL);
Display->Lines->Add(str_out);
}
}
}
}
Even better, for a directory listing you really should be using
FindFirstFile(), FindNextFile(), and FileClose() instead. Then you don't
need CreateProcess() at all.
Gambit
Technical Details
Message-ID:
<40bbabcd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40b882fd@newsgroups.borland.com> <40b8ec28$1@newsgroups.borland.com> <40bb1e04@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5907943efec0dea8 X-Google-Attributes: gid10cc67,public From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40b882fd@newsgroups.borland.com> <40b8ec28$1@newsgroups.borland.com> <40bb1e04@newsgroups.borland.com> Subject: Re: Controlling another application Date: Mon, 31 May 2004 14:59:30 -0700 Lines: 51 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 67.22.135.163 Message-ID: <40bbabcd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1086041037 67.22.135.163 (31 May 2004 15:03:57 -0700) Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail