caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Q] Callbacking a ocaml function from VC++
@ 2000-12-06  0:56 Hyun-Goo Kang
  2000-12-11  9:47 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Hyun-Goo Kang @ 2000-12-06  0:56 UTC (permalink / raw)
  To: caml-list

---------------------------------------------------------------------------
[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.







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-12-11 17:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-06  0:56 [Q] Callbacking a ocaml function from VC++ Hyun-Goo Kang
2000-12-11  9:47 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).