<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.73">
<TITLE>RE: OT: Any c++ win32 or mfc programmers here? (speech control jukebox app.)</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>jeffslists wrote:</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Right now I have a simple speech application which compiles as a </FONT>
<BR><FONT SIZE=2>> dialog-based application. I have no idea how to send output to the </FONT>
<BR><FONT SIZE=2>> console from a dialog-based app. For now I've resorted to sending </FONT>
<BR><FONT SIZE=2>> output to an edit box. (Sending output to the edit box was much more </FONT>
<BR><FONT SIZE=2>> complicated than I expected. I spent two hours trying to figure out </FONT>
<BR><FONT SIZE=2>> just how to automatically scroll the damn thing.)</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> I would rather send trace output to the console/stdout than use an </FONT>
<BR><FONT SIZE=2>> edit box. I could create a new project in MS VC 6.0 as a console </FONT>
<BR><FONT SIZE=2>> based application, which would give me easy access to the console, but I do</FONT>
<BR><FONT SIZE=2>> not know windows programming well enough to restructure the speech app .</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Here is a link to the app. I am working with:</FONT>
<BR><FONT SIZE=2>> *SAPI 5.0 Tutorial I: An Introduction to SAPI* </FONT>
<BR><FONT SIZE=2>> <<A HREF="http://www.generation5.org/content/2001/sr00.asp" TARGET="_blank">http://www.generation5.org/content/2001/sr00.asp</A>></FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Is there anyone here who can give me hand? </FONT>
</P>
<P><FONT SIZE=2>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: <A HREF="http://www.codeguru.com/console/dualmode.html" TARGET="_blank">http://www.codeguru.com/console/dualmode.html</A></FONT></P>
<P><FONT SIZE=2>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:</FONT></P>
<P><FONT SIZE=2>'winbase.h</FONT>
<BR><FONT SIZE=2>macro STD_INPUT_HANDLE = -10</FONT>
<BR><FONT SIZE=2>macro STD_OUTPUT_HANDLE = -11</FONT>
<BR><FONT SIZE=2>macro STD_ERROR_HANDLE = -12</FONT>
<BR><FONT SIZE=2>macro FILE_TYPE_UNKNOWN = &h0000</FONT>
<BR><FONT SIZE=2>macro FILE_TYPE_DISK = &h0001</FONT>
<BR><FONT SIZE=2>macro FILE_TYPE_CHAR = &h0002</FONT>
<BR><FONT SIZE=2>macro FILE_TYPE_PIPE = &h0003</FONT>
<BR><FONT SIZE=2>macro FILE_TYPE_REMOTE = &h8000</FONT>
</P>
<P><FONT SIZE=2>declare function AllocConsole% lib "kernel32.dll" ()</FONT>
<BR><FONT SIZE=2>declare function FreeConsole% lib "kernel32.dll" ()</FONT>
<BR><FONT SIZE=2>declare function GetStdHandle& lib "kernel32.dll" (hStd&) ' STD_?_HANDLE, ? = INPUT, OUTPUT, or ERROR</FONT>
<BR><FONT SIZE=2>declare function GetFileType& lib "kernel32.dll" (osfHandle&)</FONT>
<BR><FONT SIZE=2>declare function WriteFile& lib "kernel32.dll" (hFile&, szWriteBuffer$, sizeWriteBuffer&, ytesWritten as pointer to long, overlap as pointer to long)</FONT></P>
<BR>
<P><FONT SIZE=2>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)</FONT></P>
<P><FONT SIZE=2>declare function CloseHandle lib "kernel32.dll" (hObject as long) as long</FONT>
</P>
<P><FONT SIZE=2>macro CRLF = chr(10) + chr(13)</FONT>
<BR><FONT SIZE=2>macro NORMAL_PRIORITY_CLASS = &H00000020</FONT>
</P>
<P><FONT SIZE=2>type PROCESS_INFORMATION ' The PROCESS_INFO structure is used by</FONT>
<BR><FONT SIZE=2> hProcess as long ' the CreateProcessA function to return</FONT>
<BR><FONT SIZE=2> hThread as long ' information about the newly created process</FONT>
<BR><FONT SIZE=2> dwProcessId as long ' The two handles that are returned in this</FONT>
<BR><FONT SIZE=2> dwThreadId as long ' structure are open handles to the new</FONT>
<BR><FONT SIZE=2>end type ' process and its primary thread</FONT>
</P>
<P><FONT SIZE=2>type STARTUPINFOA ' The STARTUPINFOA structure allows</FONT>
<BR><FONT SIZE=2> cb as long ' the CreateProcessA function to control</FONT>
<BR><FONT SIZE=2> lpReserved as long ' many aspects of the creation process</FONT>
<BR><FONT SIZE=2> lpDesktop as long</FONT>
<BR><FONT SIZE=2> lpTitle as long</FONT>
<BR><FONT SIZE=2> dwX as long</FONT>
<BR><FONT SIZE=2> dwY as long</FONT>
<BR><FONT SIZE=2> dwXSize as long</FONT>
<BR><FONT SIZE=2> dwYSize as long</FONT>
<BR><FONT SIZE=2> dwXCountChars as long</FONT>
<BR><FONT SIZE=2> dwYCountChars as long</FONT>
<BR><FONT SIZE=2> dwFillAttribute as long</FONT>
<BR><FONT SIZE=2> dwFlags as long</FONT>
<BR><FONT SIZE=2> wShowWindow as short</FONT>
<BR><FONT SIZE=2> cbReserved2 as short</FONT>
<BR><FONT SIZE=2> lpReserved2 as long</FONT>
<BR><FONT SIZE=2> hStdInput as long</FONT>
<BR><FONT SIZE=2> hStdOutput as long</FONT>
<BR><FONT SIZE=2> hStdError as long</FONT>
<BR><FONT SIZE=2>end type</FONT>
</P>
<P><FONT SIZE=2>dim osfSTDOUT&, text$, pi as PROCESS_INFORMATION, si as STARTUPINFOA</FONT>
<BR><FONT SIZE=2>const STATEMENT$ = "How am I doing?" + chr(10) + chr(13)</FONT>
</P>
<P><FONT SIZE=2>AllocConsole</FONT>
<BR><FONT SIZE=2>osfSTDOUT = GetStdHandle(STD_OUTPUT_HANDLE)</FONT>
<BR><FONT SIZE=2>if FILE_TYPE_CHAR = GetFileType(osfSTDOUT) then</FONT>
<BR><FONT SIZE=2> WriteFile(osfSTDOUT, STATEMENT, len(STATEMENT), Null, Null)</FONT>
<BR><FONT SIZE=2> sleep 3</FONT>
<BR> <FONT SIZE=2>CreateProcess(null, "c:\winnt\system32\cmd.exe", null, null, FALSE, _</FONT>
<BR><FONT SIZE=2> NORMAL_PRIORITY_CLASS, 0, "C:\.", si, pi)</FONT>
<BR><FONT SIZE=2> sleep 10</FONT>
<BR><FONT SIZE=2>endif</FONT>
<BR><FONT SIZE=2>CloseHandle(pi.hProcess)</FONT>
<BR><FONT SIZE=2>CloseHandle(pi.hThread)</FONT>
<BR><FONT SIZE=2>FreeConsole</FONT>
</P>
<P><FONT SIZE=2>--</FONT>
<BR><FONT SIZE=2>Garrett Goebel</FONT>
<BR><FONT SIZE=2>IS Development Specialist</FONT>
</P>
<P><FONT SIZE=2>ScriptPro Direct: 913.403.5261</FONT>
<BR><FONT SIZE=2>5828 Reeds Road Main: 913.384.1008</FONT>
<BR><FONT SIZE=2>Mission, KS 66202 Fax: 913.384.2180</FONT>
<BR><FONT SIZE=2>www.scriptpro.com garrett at scriptpro dot com</FONT>
</P>
<BR>
</BODY>
</HTML>