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

Gerald Combs gerald at ethereal.com
Thu Aug 26 21:49:25 CDT 2004


jeffslists wrote:
> This may be a linux list, but the best windows programmers I've seen are
> the people who also know unix or unix programming.  I'm working on the
> speech module part of my intelligent jukebox and it seems windows is
> giving me more problems than expected.  I have a problem I'm trying to
> solve which should be simple. (I haven't done any serious windows
> programming for about 3 years.)
> 
> It sure would be nice if windows adhered more to standards, like giving
> the programmer access to stdout at all times.  I would like to send text
> to stdout or a console output so I can watch processing of my speech
> commands in real-time.  I could send the output to a file, but then I
> have to keep reloading in order to watch the output.
> 
> 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?

For Ethereal we use the following (from gtk/main.c):

--------
/*
 * If this application has no console window to which its standard
 * output would go, create one.
 */
void
create_console(void)
{
  if (!has_console && prefs.gui_console_open != console_open_never) {
    /* We have no console to which to print the version string, so
       create one and make it the standard input, output, and error. */
    if (!AllocConsole())
      return;   /* couldn't create console */
    freopen("CONIN$", "r", stdin);
    freopen("CONOUT$", "w", stdout);
    freopen("CONOUT$", "w", stderr);

    /* Well, we have a console now. */
    has_console = TRUE;

    /* Now register "destroy_console()" as a routine to be called just
       before the application exits, so that we can destroy the console
       after the user has typed a key (so that the console doesn't just
       disappear out from under them, giving the user no chance to see
       the message(s) we put in there). */
    atexit(destroy_console);
  }
}

static void
destroy_console(void)
{
  if (has_console) {
    printf("\n\nPress any key to exit\n");
    _getch();
    FreeConsole();
  }
}
--------

The whole file can be found at

http://anonsvn.ethereal.com/viewcvs/viewcvs.py/trunk/gtk/main.c


Searching MSDN for "AllocConsole" turns up the following, which describe
console access in detail:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creation_of_a_console.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/allocconsole.asp




More information about the Kclug mailing list