186cdf877113233af1aa4de50a3c262189378219
[reactos.git] / reactos / dll / appcompat / shims / shimlib / implement_shim.inl
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Shim library
4 * FILE: dll/appcompat/shims/shimlib/implement_shim.inl
5 * PURPOSE: Shimlib helper file, used to register shims setup with macro's from setup_shim.inl
6 * PROGRAMMER: Mark Jansen
7 */
8
9 #ifndef SHIM_NS
10 #error "A namespace should be provided in SHIM_NS before including this file!"
11 #endif
12
13 #ifndef SHIM_NUM_HOOKS
14 #error "The number of hooks should be provided in SHIM_NUM_HOOKS before including this file!"
15 #endif
16
17 #ifndef SHIM_OBJ_NAME
18 #error "setup_shim.inl should be included before this file!"
19 #endif
20
21 #if SHIM_NUM_HOOKS > 0
22 #ifndef SHIM_SETUP_HOOKS
23 #error "Please define a hook: #define SHIM_SETUP_HOOKS SHIM_HOOK(num, dll_name, function_name, your_function)"
24 #endif
25 #else
26 #ifdef SHIM_SETUP_HOOKS
27 #error "Hooks are defined, yet SHIM_NUM_HOOKS is <= 0 !"
28 #endif
29 #endif
30
31 PHOOKAPI WINAPI SHIM_OBJ_NAME(GetHookAPIs)(DWORD fdwReason, PCSTR pszCmdLine, PDWORD pdwHookCount)
32 {
33 if (pszCmdLine)
34 {
35 SHIM_OBJ_NAME(g_szCommandLine) = ShimLib_StringDuplicateA(pszCmdLine);
36 }
37 else
38 {
39 SHIM_OBJ_NAME(g_szCommandLine) = "";
40 }
41 SHIM_OBJ_NAME(g_pAPIHooks) = ShimLib_ShimMalloc(sizeof(HOOKAPI) * SHIM_NUM_HOOKS);
42 ZeroMemory(SHIM_OBJ_NAME(g_pAPIHooks), sizeof(HOOKAPI) * SHIM_NUM_HOOKS);
43 *pdwHookCount = SHIM_NUM_HOOKS;
44
45 #ifdef SHIM_NOTIFY_FN
46 if (!SHIM_NOTIFY_FN(fdwReason, NULL))
47 return NULL;
48 #endif
49
50 #if SHIM_NUM_HOOKS > 0
51 SHIM_SETUP_HOOKS
52 #endif
53 return SHIM_OBJ_NAME(g_pAPIHooks);
54 }
55
56
57 #if defined(_MSC_VER)
58 #pragma section(".shm$BBB",long,read)
59 #endif
60
61 _SHMALLOC(".shm$BBB") SHIMREG SHIM_OBJ_NAME(_shim_fn) =
62 {
63 SHIM_OBJ_NAME(GetHookAPIs),
64 #ifdef SHIM_NOTIFY_FN
65 SHIM_NOTIFY_FN,
66 #else
67 NULL,
68 #endif
69 SHIM_STRINGIFY(SHIM_NS)
70 };
71
72 #undef SHIM_SETUP_HOOKS
73 #undef SHIM_NOTIFY_FN
74 #undef SHIM_NUM_HOOKS
75 #undef SHIM_NS