Top-Down Structs
John C
johnch_atms at hotmail.com
Sat Mar 11 05:25:41 PST 2006
Bob W wrote:
> After using some Win32 declarations, wich are
> obviously not part of "std.c.windows.windows",
> I have noticed that a resulting program crashes with
>
> "Error: Win32 Exception" .
>
> This happens if the main structure ("INPUT_RECORD")
> is declared before the other structures contained in
> the main structure. The problem will not arise if
> sub-structs [B] are declared earlier than the main
> struct [A].
>
> Before that incident I was convinced that the
> D compiler would handle "top-down" declarations
> correctly.
>
>
>
> ----- "Problematic" declaration sequence: -----
>
>
> // INPUT_RECORD [A]
>
> 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;
> } }
>
>
> // Structs contained in INPUT_RECORD [B]
>
> struct KEY_EVENT_RECORD {
> BOOL bKeyDown;
> WORD wRepeatCount;
> WORD wVirtualKeyCode;
> WORD wVirtualScanCode;
> union { WCHAR UnicodeChar; CHAR AsciiChar; }
> DWORD dwControlKeyState;
> }
>
> struct MOUSE_EVENT_RECORD {
> COORD dwMousePosition;
> DWORD dwButtonState;
> DWORD dwControlKeyState;
> DWORD dwEventFlags;
> }
>
> struct WINDOW_BUFFER_SIZE_RECORD { COORD dwSize; }
> struct MENU_EVENT_RECORD { UINT dwCommandId; }
> struct FOCUS_EVENT_RECORD { BOOL bSetFocus; }
>
>
>
Couldn't repro on my Windows XP machine. Runs without throwing
exceptions here.
More information about the Digitalmars-d-bugs
mailing list