Hi,
I have some problems flushing the input buffer of a console using the FlushConsoleInputBuffer function. It just doesn't seem to work, even if the function return success. Maybe my vision of what is an input buffer is wrong (i always thought that if characters aren't return to you by a read function, they are considered still being in the input buffer; at least, that's how it "works" with the standard C functions). So... why isn't it working ? I'm quite lost.
Here's a simple test program i did, trying to find out what was wrong
Code:
#include <windows.h>
#include <string.h>
#define ERR() MessageBoxA(NULL, "Something went wrong somewhere", "Error", MB_OK)
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR lpCL, int nCS)
{
HANDLE stdOutputHandle;
HANDLE stdInputHandle;
DWORD dw;
BOOL b;
char c;
const char *msg1 = "Enter 'q' to quit.";
if (AllocConsole() != 0)
{
/* A: Houston, we have a console */
stdOutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if (stdOutputHandle == INVALID_HANDLE_VALUE)
ERR();
stdInputHandle = GetStdHandle(STD_INPUT_HANDLE);
if (stdInputHandle == INVALID_HANDLE_VALUE)
ERR();
do
{
WriteConsoleA(stdOutputHandle, msg1, strlen(msg1), &dw, NULL);
if (dw != strlen(msg1))
ERR();
ReadConsoleA(stdInputHandle, &c, 1, &dw, NULL);
if (dw != 1)
ERR();
if (FlushConsoleInputBuffer(stdInputHandle) == 0)
ERR();
} while (c != 'q');
FreeConsole();
}
return 0;
}
As for the compiler, I'm using Visual Studio 2005 Pro.
Thanks