English 中文(简体)
利用WINAPI ReadConsole
原标题:Using WINAPI ReadConsole

我正试图使用WINAPIReadConsole(),在我的Win32 console申请结束时等待任何关键词。

CONSOLE_READCONSOLE_CONTROL tControl;
char pStr[65536];
DWORD dwBufLen = 1;
DWORD dwCtl;

tControl_c.nLength = sizeof( CONSOLE_READCONSOLE_CONTROL );
tControl_c.nInitialChars = 0;
tControl_c.dwControlKeyState = 0;
tControl_c.dwCtrlWakeupMask = NULL;

pBuf[0] = 0x00;

do
{
   ReadConsole( hConsole_c, pStr, (*pBufLen) * sizeof(TCHAR), pBufLen, &tControl );
}
while ( pStr[0] == 0x00 );

该法典实施时没有例外。 然而,当<代码>ReadConsole()功能实施错误代码时,ERROR_INVALID_HANDLE(0x06)即为标志。 我已核实了<代码>hConsole_c为有效操作。 是否有任何人对我错做什么有任何了解? 我正在使用视觉C++2008年快版。 感谢。

最佳回答

对我的工作罚款。 我唯一能够使其失败的方法是ERROR_INVALID_ HANDLE 是通过STD_OUTPUT_HANDLE而不是STD_INPUT_HANDLE。 你们是否确信是谁?

问题回答

If you are just trying to wait for keypress at the end of your console app why dont you try System("Pause"); ?

你等待中风的方法过于复杂。 利用单一C功能电话,你可以采取多种方式:

  • getch(); (or the ISO C++ conformant name, _getch), which is platform independent;
  • system("pause");, which is Windows-specific.




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签