From: "Hyun-Goo Kang" <hgkang@ropas.kaist.ac.kr>
To: <caml-list@inria.fr>
Subject: [Q] Callbacking a ocaml function from VC++
Date: Wed, 6 Dec 2000 09:56:15 +0900 [thread overview]
Message-ID: <002c01c05f1f$55fb95b0$8e5cf88f@plus> (raw)
---------------------------------------------------------------------------
[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.
next reply other threads:[~2000-12-07 8:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-12-06 0:56 Hyun-Goo Kang [this message]
2000-12-11 9:47 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='002c01c05f1f$55fb95b0$8e5cf88f@plus' \
--to=hgkang@ropas.kaist.ac.kr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).