Hi,

I'm trying to convert some structures from C -> ASM but I don't know If I got it right...Here's the C Code
[size=9]::INPUT_RECORD::


typedef struct _INPUT_RECORD {
WORD EventType;
union {
KEY_EVENT_RECORD KeyEvent;
MOUSE_EVENT_RECORD MouseEvent;
WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
MENU_EVENT_RECORD MenuEvent;
FOCUS_EVENT_RECORD FocusEvent;
} Event;
} INPUT_RECORD;

typedef struct _KEY_EVENT_RECORD {
BOOL bKeyDown;
WORD wRepeatCount;
WORD wVirtualKeyCode;
WORD wVirtualScanCode;
union {
WCHAR UnicodeChar;
CHAR AsciiChar;
} uChar;
DWORD dwControlKeyState;
} KEY_EVENT_RECORD;

typedef struct _COORD {
SHORT X;
SHORT Y;
} COORD;

typedef struct _MOUSE_EVENT_RECORD {
COORD dwMousePosition;
DWORD dwButtonState;
DWORD dwControlKeyState;
DWORD dwEventFlags;
} MOUSE_EVENT_RECORD;

typedef struct _WINDOW_BUFFER_SIZE_RECORD {
COORD dwSize;
} WINDOW_BUFFER_SIZE_RECORD;

typedef struct _MENU_EVENT_RECORD {
UINT dwCommandId;
} MENU_EVENT_RECORD, *PMENU_EVENT_RECORD;

typedef struct _FOCUS_EVENT_RECORD {
BOOL bSetFocus;
} FOCUS_EVENT_RECORD;[/size]
Here's My ASM translation.
[size=9]INPUT_RECORD STRUCT

EventType DW ?
UNION Event
STRUCT KeyEvent
bKeyDown DD ?
wRepeatCount DW ?
wVirtualKeyCode DW ?
wVirtualScanCode DW ?
UNION uChar
UnicodeChar DW ?
AsciiChar DB ?
ENDS
dwControlKeyState DD ?
ENDS
STRUCT MouseEvent
STRUCT dwMousePosition
x DW ?
y DW ?
ENDS
dwButtonState DD ?
dwControlKeyState DD ?
dwEventFlags DD ?
ENDS
STRUCT WindowBufferSizeEvent
STRUCT dwSize
x DW ?
y DW ?
ENDS
ENDS
STRUCT MenuEvent
dwCommandId DD ?
ENDS
STRUCT FocusEvent
bSetFocus DD ?
ENDS
ENDS
INPUT_RECORD ENDS
[/size]
I tried plugging this into an API but I get wierd results in ASM. I tried coding a C version but the C version was working fine. I don't know where I went wrong. Eveything seems perfect to me... Thanks!
Posted on 2002-06-12 09:48:46 by stryker
hi stryker,

the first structure is the only structure you need to convert the others are already converted in the windows.inc.
INPUT_RECORD STRUCT

EventType WORD ?
union
KeyEvent KEY_EVENT_RECORD
MouseEvent MOUSE_EVENT_RECORD <>
WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <>
MenuEvent MENU_EVENT_RECORD <>
FocusEvent FOCUS_EVENT_RECORD <>
ends
INPUT_RECORD ENDS
Posted on 2002-06-12 10:03:25 by smurf
I tried that too but still get weird results...I'll see what I can do... Probably some logic bugs...I thought it was the structure. Thanks!!!
Posted on 2002-06-12 10:08:59 by stryker
Yay! I've solved my problem...The problem was, I was using it like this InputInfo.Event.KeyEvent.bKeyDown to get the boolean data.....I guess this doesn't work, so I disasm it and got the stack location of the INPUT_RECORD structure then I retrieve the data through base indexing... :alright:
Posted on 2002-06-12 11:22:02 by stryker
You'd have to have a conditional:
; if keyboard event

; do stuff with keyboard structure InputInfo.KeyEvent.bKeyDown

; if ? event
; do stuff with InputInfo.?.?
You have to test EventType at run-time.
Posted on 2002-06-12 11:58:53 by bitRAKE