Troubles Making a DLL from OCAML

This is a discussion on Troubles Making a DLL from OCAML within the ml forums in Programming Languages category; I have troubles making a Dll from caml. I know the CamlIdl can help to do the job, but since I have only a couple of functions I want to access from caml, I tried to do the job manually. I ran into trouble using an Array.iter command, that makes my dll to crash on the caml_startup(argv) line. Note that i call my dll from visual basic. Also when i do exactly the same, but the C code being a program and not a dll, it works fine. Here is what i have done : vb-caml.ml---------------------------- let print_array print_elem tab ...

Go Back   Application Development Forum > Programming Languages > ml

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-07-2003, 11:53 AM
ArthurC
Guest
 
Default Troubles Making a DLL from OCAML

I have troubles making a Dll from caml.

I know the CamlIdl can help to do the job,
but since I have only a couple of functions I want to access from caml,
I tried to do the job manually.

I ran into trouble using an Array.iter command,
that makes my dll to crash on the caml_startup(argv) line.

Note that i call my dll from visual basic.

Also when i do exactly the same, but the C code being a program and not a dll,
it works fine.


Here is what i have done :



vb-caml.ml----------------------------

let print_array print_elem tab =
Array.iter print_elem tab; print_newline();;

Callback.register "print_array" print_array;;

(*Actually it crashed without this register line *)


vb-caml.c-------------------------------------


#include <caml/mlvalues.h>
#include <caml/callback.h>
#include <caml/memory.h>
#include <windows.h>

#include <stdio.h>

int is_initialized = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
if (ul_reason_for_call==DLL_PROCESS_ATTACH) {
if (! is_initialized) {
char* progname = "DllCall";
char* argv[] = { progname };
caml_startup(argv);
is_initialized = 1;
}

}
return TRUE;
}


void __stdcall Test() {
printf("can you see that\n");
}

// I also tried to put the startup command in the test function.


vb-caml.def-------------------------------------

LIBRARY VB-CAML
DESCRIPTION DLL FOR VB-CAML CARD

EXPORTS

Test @1



make.bat-----------------------------------------

@echo off
ocamlc -custom -output-objvb-caml.ml -o camlcode.obj
echo /IC:\info\ocaml\lib\ /I:C:\info\Visual\VC98\INCLUDE /nologo /Fevb-
caml.dll /link /NOLOGO /DLL /def:"vb- caml.def"
/NODEFAULTLIB:LIBC /LIBPATH:C:\info\ocaml\lib\ > linkopt.txt
cl @linkopt.txt vb-caml.c camlcode.obj libcamlrun.lib



--------------


Please let me know if you can spot what I made wrong.

Thanks

Arthur

Reply With Quote
  #2  
Old 07-08-2003, 11:10 AM
Xavier Leroy
Guest
 
Default Re: Troubles Making a DLL from OCAML


> I have troubles making a Dll from caml.
> I ran into trouble using an Array.iter command,
> that makes my dll to crash on the caml_startup(argv) line.
> [...]
> if (! is_initialized) {
> char* progname = "DllCall";
> char* argv[] = { progname };
> caml_startup(argv);


The "argv" array must be NULL-terminated:

char* argv[] = { progname, NULL };
caml_startup(argv);

And, yes, this should be documented better.

- Xavier Leroy
--
Valid e-mail address (without the underscores): Xavier.Leroy@i_n_r_i_a.f_r
This is a protection against junk mail. Apologies for the inconvenience.
Home page: http://pauillac.inria.fr/~xleroy/

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:54 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.