[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Hyun-Goo Kang <hgkang@r...> |
| Subject: | [Q] Callbacking a ocaml function from VC++ |
---------------------------------------------------------------------------
[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.