From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA00707 for caml-red; Mon, 11 Dec 2000 18:44:05 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA28493 for ; Mon, 11 Dec 2000 10:48:04 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eBB9lSD11828; Mon, 11 Dec 2000 10:47:28 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA30527; Mon, 11 Dec 2000 10:47:24 +0100 (MET) Date: Mon, 11 Dec 2000 10:47:24 +0100 From: Xavier Leroy To: Hyun-Goo Kang Cc: caml-list@inria.fr Subject: Re: [Q] Callbacking a ocaml function from VC++ Message-ID: <20001211104724.B5346@pauillac.inria.fr> References: <002c01c05f1f$55fb95b0$8e5cf88f@plus> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <002c01c05f1f$55fb95b0$8e5cf88f@plus>; from hgkang@ropas.kaist.ac.kr on Wed, Dec 06, 2000 at 09:56:15AM +0900 Sender: weis@pauillac.inria.fr > [Q] Callbacking a ocaml function which uses Unix socket lib from VC++ > function" I had a look at your example. The problem is that the Caml code raises an exception, and the callback() function tries to propagate the exception upwards to Caml code that is calling the current C code, and since there is none it stops the program. Better use callback_exn() and check for exceptions yourself: int connect_it() { static value *connect = NULL; value res; if (connect == NULL) connect = caml_named_value("connect"); res = callback(*connect,Val_unit); if (Is_exception_result(res)) { // do something to report an error } else { return Int_val(res); } } Now, why is it that the Caml code raises an exception? In my test run, it's Unix.socket that raises an exception, because apparently the wsock32 subsystem hasn't been initialized. Adding the following lines in the main function cured the problem: WSADATA wsaData; (void) WSAStartup(MAKEWORD(2, 0), &wsaData); Still, this is surprising because normally the initialization of wsock32 is performed by the Caml Unix library when it starts up. I haven't been able yet to track the problem down. - Xavier Leroy