[Haskell-cafe] Doing Windows Programming

Juan Carlos Arevalo Baeza jcab.lists at JCABs-Rumblings.com
Thu Sep 15 12:49:53 EDT 2005

   GHC 6.4's support for Win32 is definitely broken. However, I've been 
experimenting with implementing a wrapper using FFI, and that has proven 
to be reasonably easy. The only gotchas:

1- You have to run ghc --make with the extra -lGdi32, -lUser32, etc... 
2- You can't use something like ghc -e:Main.main Main.hs to run Win32 
programs. As soon as you are passing function pointers around 
(WindowProcs and the like) it just won't work because of the stub.c files.
3- Safely managing function pointers can be tricky, because FuncPtr has 
to be explicitly deallocated or else it will leak.
4- If you don't want to have the console window, you have to add the 
-optl-mwindows switch to the command line (hopefully, it'll be 
documented at some point) and refrain from ever writing anything out to 
stdout or stderr. If you want to be able to write stuff out (so that you 
can see it by ommitting the switch) then do something like this:

initGUI = catch (putStr " \b" >> hFlush stdout) $ \_ -> do
    fd <- open "nul" 2 0
    dup2 fd 0
    dup2 fd 1
    dup2 fd 2
    return ()

open fname oflag pmode = withCString fname $ \c_fname -> c_open c_fname 
oflag pmode

foreign import ccall unsafe "HsBase.h __hscore_open" c_open :: CString 
-> CInt -> CInt -> IO CInt
foreign import ccall unsafe "HsBase.h dup2" dup2            :: CInt -> 
CInt -> IO CInt

   and then call initGUI from your main.

   All very platform/compiler dependent, of course, so use with good 


Neil Mitchell wrote:

>The CVS version of Hugs for Windows has a module
>System.Win32.Registry, along with quite a few other windows modules.
>I'm not sure if the last stable releases have these features in or not.
>On 9/11/05, Brian McQueen <mcqueenorama at gmail.com> wrote:
>>How can I use Haskell to do general Windows programming, like you
>>would be able to do if you were using one of those Windows IDEs:
>>*moving data between windows apps
>>*gaining access to windows registry
>>*in general, access to the available Windows APIs
>>I'm sure folks must be writing Windows apps in Haskell somewhere.  How
>>do I get started?
>>Brian McQueen
>>Haskell-Cafe mailing list
>>Haskell-Cafe at haskell.org
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20050915/d1c24b6f/attachment.htm

More information about the Haskell-Cafe mailing list