English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Win32 API
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-31 (20:34)
From: Harry Chomsky <harry@c...>
Subject: [Caml-list] Win32 API
I've embarked on a project to enable writing full-fledged Win32 applications
using OCaml.  I'm doing this mostly for fun as I take a break between jobs.
Of course I hope some people may find it useful in the end.  There's a long
way to go still, but I wanted to let the community know that I'm doing this
and see if you have any advice.  Most of all, if this has already been done,
please tell me so I can stop wasting my time!  As far as I can tell from the
mailing list archives, it has not been done yet, and a few people have
requested it.

If anyone wants to see where I am with it, and offer help or feedback, I've
posted the code at:


Much of the work is tedious, but it's been interesting trying to compensate
for Win32's tendency to use C's weak typing.  I've tried to present the API
to OCaml programmers in a strongly typed fashion consistent with the OCaml
philosophy, but still provide all the capabilities that Win32 C programmers
are used to.

The main area I'm uncomfortable with is memory management and the section of
the OCaml manual entitled "Living in harmony with the garbage collector".  I
can't tell from the manual whether I need to pay attention to all these
rules and special C macros.  I do use the C functions malloc and free
occasionally, but only in a very local fashion -- I never pass the resulting
pointers back to the OCaml program.  My C code also makes extensive use of
the functions alloc, alloc_tuple, copy_string, etc. and the macros
Store_field, etc. that are provided by the OCaml runtime library.  So far
everything "just works", but I'd like to make sure I'm not overlooking some
kind of lurking problem here.  Can someone give me a clear explanation of
when I can safely ignore rules 1 and 2?

One place where I most likely *do* have a problem is the array of "message
handler" functions that the C code stores when it registers a window class.
I think I have to register these as global roots, since in theory the OCaml
code could provide dynamically-generated closures which are at risk of being
garbage-collected.  Again, my understanding is fuzzy and I would appreciate
any advice.

To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr