bormuth
asked on
Using Win32 Console
I want to use the Win32 Console but when I call GetStdHandle, I get a handle that seems to be not valid.
The code should compile and show the following error after run:
Error: Could not receive buffer information. --> The handle is invalid.
Did I forget any init step ... ?
#include <windows.h>
#include <iostream.h>
void error(string s) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSA
FORMAT_MESSAGE_IGNORE_INSE
SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0,0);
std::cout << "Error: " << s << " --> " << (std::string)(LPCTSTR)lpMs
};
HANDLE _V_consoleOutputHandle, _V_consoleInputHandle;
void main()
{
CONSOLE_SCREEN_BUFFER_INFO
_V_consoleOutputHandle = GetStdHandle(STD_OUTPUT_HA
if (_V_consoleOutputHandle == INVALID_HANDLE_VALUE)
error("Could not create output buffer handle.");
_V_consoleInputHandle = GetStdHandle(STD_INPUT_HAN
if (_V_consoleInputHandle == INVALID_HANDLE_VALUE)
error("Could not create input buffer handle.");
if ( ! GetConsoleScreenBufferInfo
error("Could not receive buffer information.");
// .......
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try to call GetConsoleScreenBufferInfo right after You get handle of output.
If it work it seems that your identifiers are to long for your compiler settings.
Make identifiers for handles shorter or set specific option to make them available to be longer then now.
If it work it seems that your identifiers are to long for your compiler settings.
Make identifiers for handles shorter or set specific option to make them available to be longer then now.
ASKER
I used a shorter handle name nad even called GetConsoleScreenBufferInfo
I use Borland C++ 5.5 and Windows 2000.
I made empty console application on Visual C with:
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
HANDLE _V_consoleOutputHandle, _V_consoleInputHandle;
void main()
{
CONSOLE_SCREEN_BUFFER_INFO __csbi;
int err=0;
_V_consoleOutputHandle = GetStdHandle(STD_OUTPUT_HA NDLE);
if (_V_consoleOutputHandle == INVALID_HANDLE_VALUE)
err=1;
_V_consoleInputHandle = GetStdHandle(STD_INPUT_HAN DLE);
if (_V_consoleInputHandle == INVALID_HANDLE_VALUE)
err=1;
if ( ! GetConsoleScreenBufferInfo (_V_consol eOutputHan dle, &__csbi) )
err=1;
printf("%d", err);
getchar();
}
and output is 0 (OK).
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
HANDLE _V_consoleOutputHandle, _V_consoleInputHandle;
void main()
{
CONSOLE_SCREEN_BUFFER_INFO
int err=0;
_V_consoleOutputHandle = GetStdHandle(STD_OUTPUT_HA
if (_V_consoleOutputHandle == INVALID_HANDLE_VALUE)
err=1;
_V_consoleInputHandle = GetStdHandle(STD_INPUT_HAN
if (_V_consoleInputHandle == INVALID_HANDLE_VALUE)
err=1;
if ( ! GetConsoleScreenBufferInfo
err=1;
printf("%d", err);
getchar();
}
and output is 0 (OK).
May be You can try to change declaration for main function:
void main(void)
or
void main(int argc, char* argv[])
void main(void)
or
void main(int argc, char* argv[])
ASKER
OK
When I run the programm in a full screen 80*25 DOS window it works. But when I run it in a Console window (in my case 80*40) it doesn't.
ASKER
OK - it works
This code only runs on Win95 and following. My Console window was set to DOS mode ...
I gave th points to proskig because he gave me the idea that the code should work ..
http://support.microsoft.com/support/kb/articles/Q124/1/03.asp