Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

struct _KEY_EVENT_RECORD

0 views
Skip to first unread message

stan

unread,
Jan 27, 2004, 2:56:11 PM1/27/04
to
In a Win32 console app, built with Visual C++ 6.0, using the multithreaded C-runtime library, I have a thread which waits for keyboard input by calling ReadConsoleInput(). When that function returns an INPUT_RECORD with EventType == KEY_EVENT, I try to determine which key is pressed by looking at the data in the KEY_EVENT_RECORD which is part of the INPUT_RECORD. However, the elements of the KEY_EVENT_RECORD have bizarre values. By modifying my app to print out the value of all the elements, I see that all of the documented (wincon.h and online help) elements are there, but the structure seems to begin with an undocumented 16-bit element. Indeed, if I modify wincon.h to include this element in the KEY_EVENT_RECORD typedef, the values of all of the documented elements are correct.

What is wrong?

Stan.

Doug Harrison [MVP]

unread,
Jan 27, 2004, 3:59:23 PM1/27/04
to
stan wrote:

>In a Win32 console app, built with Visual C++ 6.0, using the multithreaded C-runtime library, I have a thread which waits for keyboard input by calling ReadConsoleInput(). When that function returns an INPUT_RECORD with EventType == KEY_EVENT, I try to determine which key is pressed by looking at the data in the KEY_EVENT_RECORD which is part of the INPUT_RECORD. However, the elements of the KEY_EVENT_RECORD have bizarre values. By modifying my app to print out the value of all the elements, I see that all of the documented (wincon.h and online help) elements are there, but the structure seems to begin with an undocumented 16-bit element. Indeed, if I modify wincon.h to include this element in the KEY_EVENT_RECORD typedef, the values of all of the documented elements are correct.
>
>What is wrong?

Sounds almost like an alignment issue. I'll see if I can get a definitive
answer on this.

--
Doug Harrison
Microsoft MVP - Visual C++

Doug Harrison [MVP]

unread,
Jan 27, 2004, 4:06:01 PM1/27/04
to
Doug Harrison [MVP] wrote:

BTW, if you are using #pragma pack around header files like <windows.h> or
<wincon.h>, or you are using the /Zp compiler option, stop, and please let
me know if this fixes it. Unless all the #included files use #pragma pack to
explicitly set their struct alignment, /Zp can cause your code to apply a
different alignment to these structs than was used to compile other code
(such as libraries) that use them. That's typically disastrous, so don't use
/Zp unless you're very sure of what you're doing (and what everyone you
#include is doing).

Stan

unread,
Jan 27, 2004, 4:31:05 PM1/27/04
to
Doug,

Thank you. I had set the project structure alignment to 1, which sets /Zp1 for all souce files. I set it back to the default value of 8 bytes and every works correctly.

Thanks again,
Stan.

Alexander Grigoriev

unread,
Jan 27, 2004, 11:04:22 PM1/27/04
to
AFAIR, KEY_EVENT_RECORD assumes default alignment (unlike most other
structures that include fillers to be /Zp independent). This structure bit
me sometime in 1995. It would make sense to fix the structure. Doug, can you
post MS ESC for it?

"Doug Harrison [MVP]" <d...@mvps.org> wrote in message
news:anjd1092jae0c9lhi...@4ax.com...

Doug Harrison [MVP]

unread,
Jan 28, 2004, 1:45:56 PM1/28/04
to
Alexander Grigoriev wrote:

>AFAIR, KEY_EVENT_RECORD assumes default alignment (unlike most other
>structures that include fillers to be /Zp independent). This structure bit
>me sometime in 1995. It would make sense to fix the structure. Doug, can you
>post MS ESC for it?

Will do.

0 new messages