List Info

Thread: "ocaml_beginners"::[] non-intrusive integration between dll and ocaml




"ocaml_beginners"::[] non-intrusive integration between dll and ocaml
country flaguser name
United States
2007-03-28 14:04:16

Hi everyone!

I'm planning to use ocaml as a "script" language to fast prototyping a
graphics engine and gpgpu framework.
My main problem is to find a elegant and non-intrusive way to integrate DLLs
with ocaml.
I did read the ocaml reference manual and find out a way to do this by
dinamically linking libraries to ocaml code, which preprocess the library,
extract the symbols and made them accessible (external) within the ocaml
environment. I did run some very basic tests by creating a simple DLL and
used the ocamlmktop to generate a custom loop-environemnt. I was able to
properly send integer and strings (char*) parameters from ocaml to c. I was
also able to send strings (char*) but I was not able to return strings from
c to ocaml. For the float parameter, I was not able even to send it as a
parameter (I tried to change from float to double, but without success).

Just to clarify a little bit, here is the functions that I exported from the
DLL:
int testint(int i)
{
int t = i + 3;
return(t);
}

float testfloat(float f)
{
int t = f + 3.0f;
return(f+3.0f);
}

char* teststring(char* s)
{
printf("%sn";, s);
char* s2 = &s[2];
return(s2);
}

I called the ocamlmktop this way:
ocamlmktop -o test.exe -dllib "mydll.dll"

By executing the generated test.exe , I imported the functions as follow:
# external testint : int -> int = "testint";;
external testint : int -> int = "testint"
# external testfloat : float -> float = "testfloat";;
external testfloat : float -> float = "testfloat"
# external teststring : string -> string = "teststring";;;
external teststring : string -> string = "teststring";

And then simply called:
testint(10);;
- : 13 = int

testfloat(10.0);;
*** PROGRAM CRASHES ***

teststring("hello world";);;
hello world
*** PROGRAM CRASHES ***

I know that this can be very dangerous!
But my question here is: how can I solve such problems being the more
non-intrusive as possible? (I don't want to add code within the DLL or
develop any external library just to act as a stub)

Thank you,
Kind regards,
Marcos Slomp

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )