Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

struct _KEY_EVENT_RECORD

조회수 0회
읽지 않은 첫 메시지로 건너뛰기

stan

읽지 않음,
2004. 1. 27. 오후 2:56:1104. 1. 27.
받는사람
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]

읽지 않음,
2004. 1. 27. 오후 3:59:2304. 1. 27.
받는사람
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]

읽지 않음,
2004. 1. 27. 오후 4:06:0104. 1. 27.
받는사람
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

읽지 않음,
2004. 1. 27. 오후 4:31:0504. 1. 27.
받는사람
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

읽지 않음,
2004. 1. 27. 오후 11:04:2204. 1. 27.
받는사람
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]

읽지 않음,
2004. 1. 28. 오후 1:45:5604. 1. 28.
받는사람
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개