OT: Any c++ win32 or mfc programmers here? (speech control ju kebox app.)

Garrett Goebel garrett at scriptpro.com
Mon Aug 30 07:58:30 CDT 2004


jeffslists wrote:
> 
> Right now I have a simple speech application which compiles as a 
> dialog-based application.  I have no idea how to send output to the 
> console from a dialog-based app.  For now I've resorted to sending 
> output to an edit box.  (Sending output to the edit box was much more 
> complicated than I expected.  I spent two hours trying to figure out 
> just how to automatically scroll the damn thing.)
> 
> I would rather send trace output to the console/stdout than use an 
> edit box.  I could create a new project in MS VC 6.0 as a console 
> based application, which would give me easy access to the console, but I
do
> not know windows programming well enough to restructure the speech app   .
> 
> Here is a link to the app. I am working with:
> *SAPI 5.0 Tutorial I: An Introduction to SAPI* 
> <http://www.generation5.org/content/2001/sr00.asp>
> 
> Is there anyone here who can give me hand? 

Gerald's reply reminded me that I'd faced the same issue using Rational
Visual Test. There were 2 ways I found to get access to a console from a
dialog based app. You can create a named pipe wrapper. See the following
article: http://www.codeguru.com/console/dualmode.html

Or you could go down the AllocConsole route as Gerald mentioned. Here's a
cut of proof of concept code I used in Visual Test Basic which illustrates
that route:

'winbase.h
macro STD_INPUT_HANDLE  = -10
macro STD_OUTPUT_HANDLE = -11
macro STD_ERROR_HANDLE  = -12
macro FILE_TYPE_UNKNOWN = &h0000
macro FILE_TYPE_DISK    = &h0001
macro FILE_TYPE_CHAR    = &h0002
macro FILE_TYPE_PIPE    = &h0003
macro FILE_TYPE_REMOTE  = &h8000

declare function AllocConsole% lib "kernel32.dll" ()
declare function FreeConsole% lib "kernel32.dll" ()
declare function GetStdHandle& lib "kernel32.dll" (hStd&) ' STD_?_HANDLE, ?
= INPUT, OUTPUT, or ERROR
declare function GetFileType& lib "kernel32.dll" (osfHandle&)
declare function WriteFile& lib "kernel32.dll" (hFile&, szWriteBuffer$,
sizeWriteBuffer&, ytesWritten as pointer to long, overlap as pointer to
long)


declare function CreateProcess& lib "kernel32.dll" alias "CreateProcessA"
(lpApplicationName$, lpCommandLine$, lpProcessAttributes as
SECURITY_ATTRIBUTES, lpThreadAttributes as SECURITY_ATTRIBUTES,
bInheritHandles&, dwCreationFlags&, lpEnvironment as any,
lpCurrentDirectory$, lpStartupInfo as STARTUPINFOA, lpProcessInformation as
PROCESS_INFORMATION)
declare function CloseHandle lib "kernel32.dll" (hObject as long) as long

macro CRLF = chr(10) + chr(13)
macro NORMAL_PRIORITY_CLASS = &H00000020

type PROCESS_INFORMATION      ' The PROCESS_INFO structure is used by
    hProcess        as long ' the CreateProcessA function to return
    hThread         as long ' information about the newly created process
    dwProcessId     as long  ' The two handles that are returned in this
    dwThreadId      as long  ' structure are open handles to the new
end type                      ' process and its primary thread

type STARTUPINFOA             ' The STARTUPINFOA structure allows
    cb              as long  ' the CreateProcessA function to control
    lpReserved      as long ' many aspects of the creation process
    lpDesktop       as long
    lpTitle         as long
    dwX             as long
    dwY             as long
    dwXSize         as long
    dwYSize         as long
    dwXCountChars   as long
    dwYCountChars   as long
    dwFillAttribute as long
    dwFlags         as long
    wShowWindow     as short
    cbReserved2     as short
    lpReserved2     as long
    hStdInput       as long
    hStdOutput      as long
    hStdError       as long
end type

dim osfSTDOUT&, text$, pi as PROCESS_INFORMATION, si as STARTUPINFOA
const STATEMENT$ = "How am I doing?" + chr(10) + chr(13)

AllocConsole
osfSTDOUT = GetStdHandle(STD_OUTPUT_HANDLE)
if FILE_TYPE_CHAR = GetFileType(osfSTDOUT) then
  WriteFile(osfSTDOUT, STATEMENT, len(STATEMENT), Null, Null)
  sleep 3
	CreateProcess(null, "c:\winnt\system32\cmd.exe", null, null, FALSE,
_
                 NORMAL_PRIORITY_CLASS, 0, "C:\.", si, pi)
  sleep 10
endif
CloseHandle(pi.hProcess)
CloseHandle(pi.hThread)
FreeConsole

--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          garrett at scriptpro dot com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://kclug.org/pipermail/kclug/attachments/20040830/2f7b9db8/attachment-0002.htm


More information about the Kclug mailing list