+import Foreign.C.String
+#else
+import System.IO (hPutStrLn,stderr)
+#endif
+
+-- | 'putTraceMsg' function outputs the trace message from IO monad.
+-- Usually the output stream is 'System.IO.stderr' but if the function is called
+-- from Windows GUI application then the output will be directed to the Windows
+-- debug console.
+putTraceMsg :: String -> IO ()
+putTraceMsg msg = do
+#ifndef __GLASGOW_HASKELL__
+ hPutStrLn stderr msg
+#else
+ withCString "%s\n" $ \cfmt ->
+ withCString msg $ \cmsg ->
+ debugBelch cfmt cmsg
+
+-- don't use debugBelch() directly, because we cannot call varargs functions
+-- using the FFI.
+foreign import ccall unsafe "HsBase.h debugBelch2"
+ debugBelch :: CString -> CString -> IO ()