Top-Down Structs
    Bob W 
    nospam at aol.com
       
    Fri Mar 10 03:43:33 PST 2006
    
    
  
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; }
    
    
More information about the Digitalmars-d-bugs
mailing list