Commit initial
This commit is contained in:
commit
ea1e853d0b
18
Makefile
Executable file
18
Makefile
Executable file
@ -0,0 +1,18 @@
|
||||
.PHONY: clean
|
||||
|
||||
all: tst.dll
|
||||
cp tst_stub/mytst.h test
|
||||
cp _build/default/dll/tst.dll test
|
||||
cd test && i686-w64-mingw32-gcc -o test.exe tst.dll test.c
|
||||
|
||||
clean:
|
||||
dune clean
|
||||
cd test && rm mytst.h test.exe tst.dll
|
||||
|
||||
tst.dll:
|
||||
dune build
|
||||
|
||||
test: all
|
||||
cd test && ./test.exe
|
||||
|
||||
|
13
dll/dune
Executable file
13
dll/dune
Executable file
@ -0,0 +1,13 @@
|
||||
(executable
|
||||
(name tst)
|
||||
(libraries tst_stub)
|
||||
(modes shared_object))
|
||||
|
||||
(alias
|
||||
(name install)
|
||||
(deps tst%{ext_dll}))
|
||||
|
||||
(rule
|
||||
(targets tst.ml)
|
||||
(action
|
||||
(write-file %{targets} "")))
|
1
dune-project
Executable file
1
dune-project
Executable file
@ -0,0 +1 @@
|
||||
(lang dune 1.9)
|
20
test/test.c
Executable file
20
test/test.c
Executable file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "mytst.h"
|
||||
|
||||
int main(){
|
||||
int before, after;
|
||||
|
||||
before = tst_init_ok();
|
||||
printf("Avant: %d\n", before);
|
||||
fflush(stdout);
|
||||
|
||||
tst_init();
|
||||
|
||||
after = tst_init_ok();
|
||||
printf("Après: %d\n", after);
|
||||
fflush(stdout);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
4
tst_stub/dune
Executable file
4
tst_stub/dune
Executable file
@ -0,0 +1,4 @@
|
||||
(library
|
||||
(name tst_stub)
|
||||
(c_names mytst_stub)
|
||||
(library_flags :standard -linkall))
|
3
tst_stub/mytst.h
Executable file
3
tst_stub/mytst.h
Executable file
@ -0,0 +1,3 @@
|
||||
void tst_init();
|
||||
int tst_init_ok();
|
||||
/* int tst_sum(int a, int b); */
|
87
tst_stub/mytst_stub.c
Executable file
87
tst_stub/mytst_stub.c
Executable file
@ -0,0 +1,87 @@
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <caml/mlvalues.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <caml/memory.h>
|
||||
#include <caml/callback.h>
|
||||
|
||||
#include "mytst.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define TST_DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define TST_DLL_EXPORT
|
||||
#endif
|
||||
|
||||
value dummy(value u){
|
||||
CAMLparam1(u);
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
static int tst_init_done = 0;
|
||||
|
||||
TST_DLL_EXPORT void
|
||||
tst_init (void)
|
||||
{
|
||||
char_os *vide[1];
|
||||
|
||||
vide[0] = NULL;
|
||||
|
||||
if (!tst_init_done)
|
||||
{
|
||||
caml_startup_exn (vide);
|
||||
tst_init_done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
TST_DLL_EXPORT int tst_init_ok (void)
|
||||
{
|
||||
return tst_init_done;
|
||||
}
|
||||
|
||||
/* TST_DLL_EXPORT int tst_sum(int a, int b){ */
|
||||
/* CAMLparam0 (); */
|
||||
/* static value *cbk = NULL; */
|
||||
/* if (cbk == NULL) */
|
||||
/* cbk = caml_named_value("additionner"); */
|
||||
/* assert(cbk); */
|
||||
/* CAMLlocal1(res); */
|
||||
/* res = caml_callback2(*cbk, Val_int(a), Val_int(b)); */
|
||||
/* CAMLreturnT(int, Int_val(res)); */
|
||||
/* } */
|
||||
|
||||
#ifdef WIN32
|
||||
BOOL WINAPI DllMain(
|
||||
HINSTANCE hinstDLL, // handle to DLL module
|
||||
DWORD fdwReason, // reason for calling function
|
||||
LPVOID lpReserved ) // reserved
|
||||
{
|
||||
|
||||
// Perform actions based on the reason for calling.
|
||||
switch( fdwReason )
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
// Initialize once for each new process.
|
||||
// Return FALSE to fail DLL load.
|
||||
/* ms_miniscan_init(); */
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
// Do thread-specific initialization.
|
||||
break;
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
// Do thread-specific cleanup.
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
// Perform any necessary cleanup.
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user