Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Built-in way to get the standard handles?

May
13,044
175
In particular, is there a built-in way to get the STD_INPUT_HANDLE?
 
Never mind. This works.

Code:
v:\> echo %@fileopen[con:,r]
88
 
Why does the GetStdHandle API return a different result?
Code:
@setlocal
@echo off
set ConA=%@fileopen[con:,r]

set STD_OUTPUT_HANDLE=%@convert[16,10,FFFFFFF5???]
set STD_INPUT_HANDLE=%@convert[16,10,FFFFFFF6???]

echo STD_OUTPUT_HANDLE: %STD_OUTPUT_HANDLE
echo  STD_INPUT_HANDLE: %STD_INPUT_HANDLE

set ConAA=%@winapi[kernel32.dll,GetStdHandle,%STD_OUTPUT_HANDLE]

echo    Using @fileopen: %ConA
echo Using GetStdHandle: %ConAA
@endlocal
Code:
E:\Utils>GetStdHandle.btm 
STD_OUTPUT_HANDLE: 4294967285
 STD_INPUT_HANDLE: 4294967286
   Using @fileopen: 80
Using GetStdHandle: 84

Joe
 
%@Fileopen[con:,r] is the input handle.

Your script asked for the output handle. With a small modification ...

Code:
v:\> grep winapi joe.btm
set ConAA=%@winapi[kernel32.dll,GetStdHandle,%STD_INPUT_HANDLE]

v:\> joe.btm
STD_OUTPUT_HANDLE: 4294967285
 STD_INPUT_HANDLE: 4294967286
   Using @fileopen: 88
Using GetStdHandle: 88
 
??? is a type-specifier in PowerBASIC,
which forces hexadecimal values to evaluate as unsigned.

In PowerBASIC, &HFFFFFFF6 is treated as a signed long-integer.

In PowerBASIC, &HFFFFFFF6??? is treated as an unsigned double-word.

Cut-and-Paste from the PowerBASIC WinBase.inc file;
Code:
::
:: %STD_INPUT_HANDLE  = &HFFFFFFF6???  '(DWORD)-10
:: %STD_OUTPUT_HANDLE = &HFFFFFFF5???  '(DWORD)-11
:: %STD_ERROR_HANDLE  = &HFFFFFFF4???  '(DWORD)-12
:

Forgot to remove them after pasting to my .btm.

Looks like @convert ignores them...
Code:
E:\Utils>echo %@convert[16,10,FFFFFFF6???]
4294967286

E:\Utils>echo %@convert[16,10,FFFFFFF6]
4294967286

Joe
 
Yeah, I saw that. Apparently it just stops reading when it encounters a character not in [0-9a-zA-Z] and later chokes if a character isn't valid in the specified input base.

Code:
v:\> echo %@convert[16,10,F!FFFFFF5]
15

v:\> echo %@convert[15,10,F!FFFFFF5]
TCC: (Sys) The parameter is incorrect.
 "%@convert[15,10,F!FFFFFF5]"
 
Back
Top
[FOX] Ultimate Translator
Translate