Re: Porting app using GetStdHandle

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: John Spaith [MS] (jspaith_at_ONLINE.microsoft.com)
Date: 09/14/04


Date: Mon, 13 Sep 2004 18:10:11 -0700

I believe that in general if stdin is redirected to your application, then
when your app calls scanf() or whatever then the c-runtime should just make
the right data show up. I don't quite know how redirection is setup on
PocketPC's, since PocketPC doesn't ship cmd.exe, which is the only app I
know that would ever change stdin based on file redirection. So this may be
an unneeded feature on CE.

Assuming you need to do this after all, looking at stdlib.h, there are these
definitions:

// Std handle defns
#define stdin _getstdfilex(0)
#define stdout _getstdfilex(1)
#define stderr _getstdfilex(2)

_getstdfilex is itself a function declared as:
_CRTIMP FILE* __cdecl _getstdfilex(int);

So you may be able to call "FILE *f = stdin;" and then use the "UNIXy"
filesys API's that take FILE* as an argument, like fread().

If this fails -- CE has a function named GetStdioPathW(). This won't give
you a handle, but will give you the prefix of the driver that is currently
giving your app STDIN - i.e. "CON3:" for console based apps or "TEL5:" for
telnet server. You may be able to take this prefix string and call
CreateFile() on it, then call ReadFile() on the returned handle. Emphasis
on "may" since I'm not sure if this will work or not.

-- 
John Spaith
Software Design Engineer, Windows CE
Microsoft Corporation
Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2003 Microsoft Corporation. All rights 
reserved.
"Thomas Canter" <zigky48v3dehqi89w6az9opc7d6yfpxw@earthlink.net> wrote in 
message news:Cel1d.304$mb6.1@newsread3.news.atl.earthlink.net...
>I would like to port a C++ application, and I am checking to see if there 
>is
> a one-to-one replacement for the GetStdHandle function call.
>
> This functionality is not critical to the application, but I want to make
> sure that I don't miss an opportunity to include this functionality 
> (reading
> from a redirected STDINPUT) on my app.
>
> Thanks,
> Tom
>
> 


Relevant Pages

  • Re: Group Policy
    ... in my case it wasn't that the files were being synchronized (disabling offline files didn't help) - but that the app referenced the %AppData% environment variable - which would return the UNC path to the server share where the user's Application Data was referenced. ... the only fix was to disable folder redirection for Application Data so that the %AppData% variable would return a local path which is what the app was expecting / assuming. ...
    (microsoft.public.windows.server.sbs)
  • Re: Editable input from the console windows
    ... stdin, stdout, and stderror in relationship to pipe commands. ... I understand the fundamentals behind redirection. ... The exec command adds to the confusion as well. ... I learning the syntax and build upon a previously working script. ...
    (comp.unix.shell)
  • Re: SIGALRM deferred during read() ?
    ... > I'm writing an app which sets an alarm, copies stdin to a file, and ... > The first version set a flag in the alarm handler, ... The app ... > time I can send SIGALRM manually as much as I wish, ...
    (comp.os.linux.development.apps)
  • Re: SIGALRM deferred during read() ?
    ... > I'm writing an app which sets an alarm, copies stdin to a file, and ... > The first version set a flag in the alarm handler, ... The app ... > time I can send SIGALRM manually as much as I wish, ...
    (comp.unix.programmer)
  • Re: A bit of grep and regex help?
    ... And here I was thinking redirection was implemented via close and open (ie ... the shell process having nothing to do as the stdin of the command ... connect write of pipe to stdout ...
    (alt.os.linux)