commit ea1e853d0bdc57391c112206cf4a9884bdddb918 Author: Matthieu Dubuget Date: Sat Apr 13 13:47:57 2019 +0200 Commit initial diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..ff030e2 --- /dev/null +++ b/Makefile @@ -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 + + diff --git a/dll/dune b/dll/dune new file mode 100755 index 0000000..b9f5815 --- /dev/null +++ b/dll/dune @@ -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} ""))) \ No newline at end of file diff --git a/dune-project b/dune-project new file mode 100755 index 0000000..1b19a0b --- /dev/null +++ b/dune-project @@ -0,0 +1 @@ +(lang dune 1.9) diff --git a/test/test.c b/test/test.c new file mode 100755 index 0000000..47c55da --- /dev/null +++ b/test/test.c @@ -0,0 +1,20 @@ +#include +#include +#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; + +} diff --git a/tst_stub/dune b/tst_stub/dune new file mode 100755 index 0000000..999f69d --- /dev/null +++ b/tst_stub/dune @@ -0,0 +1,4 @@ +(library +(name tst_stub) +(c_names mytst_stub) +(library_flags :standard -linkall)) \ No newline at end of file diff --git a/tst_stub/mytst.h b/tst_stub/mytst.h new file mode 100755 index 0000000..57b4878 --- /dev/null +++ b/tst_stub/mytst.h @@ -0,0 +1,3 @@ +void tst_init(); +int tst_init_ok(); +/* int tst_sum(int a, int b); */ diff --git a/tst_stub/mytst_stub.c b/tst_stub/mytst_stub.c new file mode 100755 index 0000000..1e9cd27 --- /dev/null +++ b/tst_stub/mytst_stub.c @@ -0,0 +1,87 @@ +#ifdef WIN32 +#include +#endif + +#include +#include +#include +#include +#include + +#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