6 Try to set up function pointers.
7 In this first implementation it is not an error if we can't load them
8 because we aren't currently trying to load any functions which we
9 absolutely need. If we later add some indispensible imports we can
10 return non-zero here to force an application exit.
12 HMODULE get_dll(const TCHAR *dll, unsigned long *error) {
15 HMODULE ret = LoadLibrary(dll);
17 *error = GetLastError();
18 log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_LOADLIBRARY_FAILED, dll, error_string(*error));
24 FARPROC get_import(HMODULE library, const char *function, unsigned long *error) {
27 FARPROC ret = GetProcAddress(library, function);
29 *error = GetLastError();
30 log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function, error_string(*error));
39 ZeroMemory(&imports, sizeof(imports));
41 imports.kernel32 = get_dll(_T("kernel32.dll"), &error);
42 if (imports.kernel32) {
43 imports.AttachConsole = (AttachConsole_ptr) get_import(imports.kernel32, "AttachConsole", &error);
44 if (! imports.AttachConsole) {
45 if (error != ERROR_PROC_NOT_FOUND) return 2;
48 imports.SleepConditionVariableCS = (SleepConditionVariableCS_ptr) get_import(imports.kernel32, "SleepConditionVariableCS", &error);
49 if (! imports.SleepConditionVariableCS) {
50 if (error != ERROR_PROC_NOT_FOUND) return 3;
53 imports.WakeConditionVariable = (WakeConditionVariable_ptr) get_import(imports.kernel32, "WakeConditionVariable", &error);
54 if (! imports.WakeConditionVariable) {
55 if (error != ERROR_PROC_NOT_FOUND) return 4;
58 else if (error != ERROR_MOD_NOT_FOUND) return 1;
64 if (imports.kernel32) FreeLibrary(imports.kernel32);
65 ZeroMemory(&imports, sizeof(imports));