I have inspected wine source code and found the following information:
environ.c implements the function as follows:
HANDLE http://www.winehq.com/source/memory/ident?i=HANDLE WINAPI http://www.winehq.com/source/memory/ident?i=WINAPI GetStdHandle http://www.winehq.com/source/memory/ident?i=GetStdHandle( DWORD http://www.winehq.com/source/memory/ident?i=DWORD std_handle ) 609 http://www.winehq.com/source/memory/source/memory/environ.c#L609 { 610 http://www.winehq.com/source/memory/source/memory/environ.c#L610 switch(std_handle) 611 http://www.winehq.com/source/memory/source/memory/environ.c#L611 { 612 http://www.winehq.com/source/memory/source/memory/environ.c#L612 case STD_INPUT_HANDLE http://www.winehq.com/source/memory/ident?i=STD_INPUT_HANDLE: return current_envdb http://www.winehq.com/source/memory/ident?i=current_envdb.hStdin; 613 http://www.winehq.com/source/memory/source/memory/environ.c#L613 case STD_OUTPUT_HANDLE http://www.winehq.com/source/memory/ident?i=STD_OUTPUT_HANDLE: return current_envdb http://www.winehq.com/source/memory/ident?i=current_envdb.hStdout; 614 http://www.winehq.com/source/memory/source/memory/environ.c#L614 case STD_ERROR_HANDLE http://www.winehq.com/source/memory/ident?i=STD_ERROR_HANDLE: return current_envdb http://www.winehq.com/source/memory/ident?i=current_envdb.hStderr; 615 http://www.winehq.com/source/memory/source/memory/environ.c#L615 } 616 http://www.winehq.com/source/memory/source/memory/environ.c#L616 SetLastError( ERROR_INVALID_PARAMETER http://www.winehq.com/source/memory/ident?i=ERROR_INVALID_PARAMETER ); 617 http://www.winehq.com/source/memory/source/memory/environ.c#L617 return INVALID_HANDLE_VALUE http://www.winehq.com/source/memory/ident?i=INVALID_HANDLE_VALUE; 618 http://www.winehq.com/source/memory/source/memory/environ.c#L618 } 619 http://www.winehq.com/source/memory/source/memory/environ.c#L619
So the function returns current_envdb.hStdin. or current_envdb.hStdout. Inspecting current_envdb structure also in environ.c:
92 http://www.winehq.com/source/memory/source/memory/environ.c#L92 ENVDB http://www.winehq.com/source/memory/ident?i=ENVDB current_envdb http://www.winehq.com/source/memory/ident?i=current_envdb = 93 http://www.winehq.com/source/memory/source/memory/environ.c#L93 { 94 http://www.winehq.com/source/memory/source/memory/environ.c#L94 0, /* environ */ 95 http://www.winehq.com/source/memory/source/memory/environ.c#L95 0, /* unknown1 */ 96 http://www.winehq.com/source/memory/source/memory/environ.c#L96 0, /* cmd_line */ 97 http://www.winehq.com/source/memory/source/memory/environ.c#L97 0, /* cur_dir */ 98 http://www.winehq.com/source/memory/source/memory/environ.c#L98 ¤t_startupinfo http://www.winehq.com/source/memory/ident?i=current_startupinfo, /* startup_info */ 99 http://www.winehq.com/source/memory/source/memory/environ.c#L99 0, /* hStdin */ 100 http://www.winehq.com/source/memory/source/memory/environ.c#L100 0, /* hStdout */ 101 http://www.winehq.com/source/memory/source/memory/environ.c#L101 0, /* hStderr */ 102 http://www.winehq.com/source/memory/source/memory/environ.c#L102 0, /* unknown2 */ 103 http://www.winehq.com/source/memory/source/memory/environ.c#L103 0, /* inherit_console */ 104 http://www.winehq.com/source/memory/source/memory/environ.c#L104 0, /* break_type */ 105 http://www.winehq.com/source/memory/source/memory/environ.c#L105 0, /* break_sem */ 106 http://www.winehq.com/source/memory/source/memory/environ.c#L106 0, /* break_event */ 107 http://www.winehq.com/source/memory/source/memory/environ.c#L107 0, /* break_thread */ 108 http://www.winehq.com/source/memory/source/memory/environ.c#L108 0 /* break_handlers */ 109 http://www.winehq.com/source/memory/source/memory/environ.c#L109 };
hStdin and hStdout are always 0. So that's the value the function always will return. I've tested it in Win32 enviroment and returns a number corresponding to the specific handler for each call. 7 and 8 are the usual numbers. I could supose 0 as a valid number in wine, but FlushConsoleInputBuffer(conhanin) fails and tells me I'm using a wrong handler.
Does anyone know more about this GetStdHandle implementation ?
Why is current_envdb set to 0 values ?
Thanks in advance, Ignasi Villagrasa.
hStdin and hStdout are always 0. So that's the value the function always will return. I've tested it in Win32 enviroment and returns a number corresponding to the specific handler for each call. 7 and 8 are the usual numbers. I could supose 0 as a valid number in wine, but FlushConsoleInputBuffer(conhanin) fails and tells me I'm using a wrong handler.
those slots are (normally) set when programs starts up, using the SetStdHandle calls (see scheduler/process.c for example)
if you get 0, it (just) means that we have to found out why the initialization process fails in your case (you should get a non zero value)
A+