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 JAA01513 for caml-red; Thu, 7 Dec 2000 09:07:10 +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 BAA01773 for ; Wed, 6 Dec 2000 01:52:32 +0100 (MET) Received: from ropas.kaist.ac.kr (ropas.kaist.ac.kr [143.248.92.105]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eB60qUP21271 for ; Wed, 6 Dec 2000 01:52:31 +0100 (MET) Received: from plus (plus.kaist.ac.kr [143.248.92.142]) by ropas.kaist.ac.kr (8.9.3/8.9.3) with SMTP id JAA10824 for ; Wed, 6 Dec 2000 09:51:43 +0900 (KST) Message-ID: <002c01c05f1f$55fb95b0$8e5cf88f@plus> Reply-To: "Hyun-Goo Kang" From: "Hyun-Goo Kang" To: Subject: [Q] Callbacking a ocaml function from VC++ Date: Wed, 6 Dec 2000 09:56:15 +0900 Organization: ropas MIME-Version: 1.0 Content-Type: text/plain; charset="ks_c_5601-1987" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: weis@pauillac.inria.fr --------------------------------------------------------------------------- [Q] Callbacking a ocaml function which uses Unix socket lib from VC++ function" --------------------------------------------------------------------------- Hello. I'm writing a network program written in ocaml3.0 for win32(for networking) and VC++6.0(for user interface). My problem is using a ocaml function which uses ocaml unix library for socket programming in a VC++ program. First i defined a function which use "Unix.connect" like following... let connect_server () = let ip = xxx.xxx.xxx.xxx in let port = 6765 in let sockfd = socket PF_INET SOCK_STREAM 0 in let target_addr = ADDR_INET(inet_addr_of_string ip,port) in let _ = connect sockfd target_addr (* try to make connection *) in (* sockfd *) 1;; (* this function was already tested in ocaml and operated properly *) and then to use callback mechanism, i registered that function like following... let _ = Callback.register "connect" connect_server and then i compiled it like following... c:\project> ocamlc -output-obj -o connect.obj unix.cma threads.cma connect.cmo and then i appended the object(connect.obj) in VC project, and libcamlrun.lib libunix.lib and wsock32.lib(if i don't append this, there are many link error), ---> (*) and then i included whole header files needed for callback like following //stdafx.h extern "C" { #include "./ocaml_lib/mlvalues.h" #include "./ocaml_lib/callback.h" } and then i called ocaml connect function in VC++ program like following... int connect_it() { static value *connect = NULL; if (connect == NULL) connect = caml_named_value("connect"); return Int_val(callback(*connect,Val_unit)); } void CDlg2Dlg::OnConnect() { int v; char** argv = (char**)malloc(sizeof(char*));; char buff[100]; *argv = NULL; //"dummy"; caml_startup(argv); sprintf(buff,"result = %d",connect_it()); AfxMessageBox(TEXT(buff)); } But i couldn't get proper result. (VC++ program termination in callback point) What is the problem? I think it's likely that the problem is in (*) point. Thanks in advance... ------------ Note: I succeeded in other easy example using same style, if i don't use Unix or Unix socket library.