A strange one

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
This happened:

g:\projects\4console\release> vbeep 3asteri 7
Usage : TITLE [/P] title

And here's the code that produced it:

INT WINAPI VBEEP ( WCHAR *psz )
{
if ( wcsstr(psz, L"/?") )
{
Printf(L"%s\r\n", item[ivbeep].Help);
return 0;
}
COORD cdZero = {0, 0};
DWORD dwWritten, dwDuration = 0, dwFreq = 0;
WCHAR junk[32] = L"";
Sscanf(psz, L" %s %u", junk, &dwDuration);

CONSOLE_CURSOR_INFO cci = {1, FALSE};
CONSOLE_SCREEN_BUFFER_INFO csbi;

GetConsoleScreenBufferInfo(STD_OUT, &csbi);

HANDLE hBlink = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0,
NULL, CONSOLE_TEXTMODE_BUFFER, NULL);

HANDLE hSave = STD_OUT;

WORD dbga = ((csbi.wAttributes & 0x00f0) >> 4) | ((csbi.wAttributes & 0x000f) << 4);

SetConsoleTextAttribute(hBlink, dbga);

SetConsoleCursorInfo(hBlink, &cci);

SetConsoleScreenBufferSize(hBlink, csbi.dwSize);
SetConsoleWindowInfo(hBlink, TRUE, &csbi.srWindow);
SetConsoleScreenBufferSize(hBlink, csbi.dwSize);

GetConsoleScreenBufferInfo(hBlink, &csbi);

FillConsoleOutputAttribute(hBlink, dbga,
(csbi.dwSize.X) * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1),
cdZero, &dwWritten);

SetConsoleActiveScreenBuffer(hBlink);

Beep_Cmd(psz);
if ( junk[0] > L'9' )
Sleep(dwDuration ? dwDuration * 1000 / 18 : 300);

SetConsoleActiveScreenBuffer(hSave);

CloseHandle(hBlink);
return 0;

It's not 100% reproducible. Sometimes I get (the expected)

g:\projects\4console\release> vbeep 3asteri 7
Usage : BEEP [ASTERISK | EXCLAMATION | HAND | OK | QUESTION] [frequency duration
...]

And note, UpdateTitle=No.
 
#2
I whittled it down:

INT WINAPI VBEEP ( WCHAR *psz )
{
return Beep_Cmd(psz);
}

Apparently, when there's a syntax error in Beep_Cmd(), I see the last used syntax message. It's the same with v8, v9, and v10.

v:\> md
Usage : MD [/N[et] /S] path...

v:\> vbeep 3asterisk 7
Usage : MD [/N[et] /S] path...

v:\> title
Usage : TITLE [/P] title

v:\> vbeep 3asterisk 7
Usage : TITLE [/P] title

v:\> unset
Usage : UNSET [/D /E /Q /R file... /S /U /V (name...)] name...

v:\> vbeep 3asterisk 7
Usage : UNSET [/D /E /Q /R file... /S /U /V (name...)] name...
 
#3
I whittled it down:

INT WINAPI VBEEP ( WCHAR *psz )
{
return Beep_Cmd(psz);
}

Apparently, when there's a syntax error in Beep_Cmd(), I see the last used syntax message. It's the same with v8, v9, and v10.
I can replace Beep_Cmd() above with another built-in and see the same results.
I guess you just don't do that! Can you explain, Rex? It's better if I do this:

WCHAR szCmd[4096] = L"BEEP ";
lstrcat(szCmd, psz);
Command(szCmd, 0);