Doing Windows Programming
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
Hi, 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. Thanks Neil On 9/11/05, Brian McQueen <mcqueenorama@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
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... switches. 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: ---8<--------------------------- 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 ---8<--------------------------- and then call initGUI from your main. All very platform/compiler dependent, of course, so use with good judgement. JCAB Neil Mitchell wrote:
Hi,
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.
Thanks
Neil
On 9/11/05, Brian McQueen <mcqueenorama@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Thanks for this! That is helpful and eye-opening. I do want to use ghc, though I don't really have a good reason for that choice. It seems that if I were to go with hugs, it would be easier going. On 9/15/05, Juan Carlos Arevalo Baeza <jcab.lists@jcabs-rumblings.com> wrote:
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... switches. 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:
---8<--------------------------- 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 ---8<---------------------------
and then call initGUI from your main.
All very platform/compiler dependent, of course, so use with good judgement.
JCAB
Neil Mitchell wrote: Hi,
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.
Thanks
Neil
On 9/11/05, Brian McQueen <mcqueenorama@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Hi, I have also just started that. I have tried the windows library with WinHugs, the wrapper librabry SOEGraphics from the author of the School of Expression book. These are just apart of another big library and c++ linker, but easier. Right now I have a hugs dotnet interpreter with a library, I think you'll find it, it's called Hugs.net and works excellent with the dotnet framework and delegates to a windows dotnet function for example. The SOE graphics is more or less for clicking with the mouse, quite simple, but worth trying. I have also tried a DirectX library called Fran, but the examples had a tendency to crash. SOE is perfect and works with unix code, almost no difference. None of these libraries works with GHC, though. There is a .NET version out that will compile and works with Visual Studio IDE, but I haven't tried it. It will compile to .NET code, at least they say so. I think you'll find it, it's called haskell.net or something like that. Also, as I mentioned, the SOE and those libraries are ripped from a C++ linker, where you can use OpenGL, it's quite big and I haven't tried it either, since the installation failed me, but then you'll get absolutely everything, search for HGL I guess it's called. Sincerely Ther Jessica Simpson fan --- Brian McQueen <mcqueenorama@gmail.com> skrev:
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Brian McQueen <mcqueenorama@gmail.com> writes:
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:
You may find H/Direct would help with this. Unfortunately, there isn't a binary build that I can find, you need to build from source (which I've not managed to achieve). If you can get a binary version, though, it's worth a look... Paul. -- It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that. -- G. H. Hardy
participants (5)
-
Brian McQueen -
Jessica Fan -
Juan Carlos Arevalo Baeza -
Neil Mitchell -
Paul Moore