+#include "../../includes/config.h"
+
+#ifdef mingw32_HOST_OS
+-- import Win32DLL
+import Foreign.C.String (CString, peekCString)
+import Foreign.C.Types
+import Foreign.Ptr (nullPtr)
+import Foreign.Marshal.Alloc (mallocBytes, free)
+
+foreign import stdcall "GetModuleHandle" c_GetModuleHandle :: CString -> IO CUInt
+foreign import stdcall "GetModuleFileName" c_GetModuleFilename :: CUInt -> CString -> CUInt -> IO CUInt
+
+ourName :: IO String
+ourName = do h <- c_GetModuleHandle nullPtr
+ cstr <- mallocBytes cstr_len
+ rv <- c_GetModuleFilename h cstr (CUInt (fromIntegral cstr_len))
+ str <- peekCString cstr
+ free cstr
+ return str
+ where cstr_len = 512
+#endif
+