Graphics.Win32.GDI.Clip.enumClipboardFormats fails on success.
According to the documentation for the Win32 !EnumClipboardFormats function:
http://msdn.microsoft.com/en-us/library/ms649038(VS.85).aspx
A return value of zero is only an error if a subsequent call to !GetLastError does not return ERROR_SUCCESS. The following code is what I would expect:
errorWinNotErrorSuccess :: (Num a) => String -> IO a
errorWinNotErrorSuccess fn_name = do
err_code <- getLastError
if err_code == 0 then return 0 else failWith fn_name err_code
failIfZeroAndNotErrorSuccess :: Num a => String -> IO a -> IO a
failIfZeroAndNotErrorSuccess wh act = do
v <- act
if v == 0 then errorWinNotErrorSuccess wh else return v
enumClipboardFormats :: ClipboardFormat -> IO ClipboardFormat
enumClipboardFormats format =
failIfZeroAndNotErrorSuccess "EnumClipboardFormats" $ c_EnumClipboardFormats format
Instead of the current:
enumClipboardFormats :: ClipboardFormat -> IO ClipboardFormat
enumClipboardFormats format =
failIfZero "EnumClipboardFormats" $ c_EnumClipboardFormats format