forked from ocaml/flexdll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexdll_initer.c
54 lines (41 loc) · 1.3 KB
/
flexdll_initer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*****************************************************************
FlexDLL
Alain Frisch
Copyright 2007 Institut National de Recherche en Informatique et
en Automatique.
******************************************************************/
/* Custom entry point to perform relocations before the real
entry point is called */
/* The adress of the flexdll_relocate function is passed in an
environment variable. This is ugly, but I couldn't find a cleaner
solution. Let me know if you have some idea! */
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
typedef int func(void*);
extern int reloctbl;
static int flexdll_init() {
func *sym = 0;
char *s = getenv("FLEXDLL_RELOCATE");
if (!s) { fprintf(stderr, "Cannot find FLEXDLL_RELOCATE\n"); return FALSE; }
sscanf(s,"%p",&sym);
if (sym && sym(&reloctbl)) return TRUE;
return FALSE;
}
#ifdef __GNUC__
#ifdef __CYGWIN__
#define entry _cygwin_dll_entry
#endif
#ifdef __MINGW32__
#define entry DllMainCRTStartup
#endif
#else
#define entry _DllMainCRTStartup
#endif
BOOL WINAPI entry(HINSTANCE, DWORD, LPVOID);
BOOL WINAPI FlexDLLiniter(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved) {
if (fdwReason == DLL_PROCESS_ATTACH && !flexdll_init())
return FALSE;
return entry(hinstDLL, fdwReason, lpReserved);
}