[C2hs] How to access inside a union using #set

Mark Wassell mwassell at bigpond.net.au
Thu Apr 2 03:42:43 EDT 2009


Hello,

I have the following:

typedef struct tagKEYBDINPUT {
    WORD wVk;
    WORD wScan;
    DWORD dwFlags;
    DWORD time;
    ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT;

typedef struct tagINPUT {
  DWORD type;
  union {MOUSEINPUT mi;
            KEYBDINPUT ki;
            HARDWAREINPUT hi;
           };
}INPUT, *PINPUT;

and in a chs file:

sendChar :: HWND -> Char -> IO ()
sendChar win ch = do
                      allocaBytes ( {#sizeof INPUT#}) $ \ptr ->
                        {#set INPUT.type #} ptr 0
                        {#set INPUT.ki.wVk #} ptr 0
                        {#set INPUT.ki.dwFlags #} ptr 0

c2hs comes up with


Test1.chs:27: (column 37) [ERROR]  >>> error
  Unknown member name!
  The structure has no member called `ki'.  The structure is defined at
  ("sendinput.h",35,9).
Test1.chs:26: (column 37) [ERROR]  >>> error
  Unknown member name!
  The structure has no member called `ki'.  The structure is defined at
  ("sendinput.h",35,9).

How do I address fields inside the union?

Cheers

Mark



More information about the C2hs mailing list