X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=imports.cpp;h=d0970bdc8a894d5e28c87921c5e03bb1ed731e1f;hb=73dbba7a2e6150dea8f58dd2c25ab914a0636308;hp=49483d495dfc850696f0a37ce327229bcb2d1183;hpb=e42e6900a5dad50b952d92c57344fdea2e13646e;p=nssm.git diff --git a/imports.cpp b/imports.cpp index 49483d4..d0970bd 100644 --- a/imports.cpp +++ b/imports.cpp @@ -9,13 +9,13 @@ imports_t imports; absolutely need. If we later add some indispensible imports we can return non-zero here to force an application exit. */ -HMODULE get_dll(const char *dll, unsigned long *error) { +HMODULE get_dll(const TCHAR *dll, unsigned long *error) { *error = 0; HMODULE ret = LoadLibrary(dll); if (! ret) { *error = GetLastError(); - log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_LOADLIBRARY_FAILED, dll, error_string(*error)); + log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_LOADLIBRARY_FAILED, dll, error_string(*error), 0); } return ret; @@ -27,7 +27,19 @@ FARPROC get_import(HMODULE library, const char *function, unsigned long *error) FARPROC ret = GetProcAddress(library, function); if (! ret) { *error = GetLastError(); - log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function, error_string(*error)); + TCHAR *function_name; +#ifdef UNICODE + size_t buflen; + mbstowcs_s(&buflen, NULL, 0, function, _TRUNCATE); + function_name = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, buflen * sizeof(TCHAR)); + if (function_name) mbstowcs_s(&buflen, function_name, buflen * sizeof(TCHAR), function, _TRUNCATE); +#else + function_name = (TCHAR *) function; +#endif + log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function_name, error_string(*error), 0); +#ifdef UNICODE + if (function_name) HeapFree(GetProcessHeap(), 0, function_name); +#endif } return ret; @@ -38,12 +50,22 @@ int get_imports() { ZeroMemory(&imports, sizeof(imports)); - imports.kernel32 = get_dll("kernel32.dll", &error); + imports.kernel32 = get_dll(_T("kernel32.dll"), &error); if (imports.kernel32) { imports.AttachConsole = (AttachConsole_ptr) get_import(imports.kernel32, "AttachConsole", &error); if (! imports.AttachConsole) { if (error != ERROR_PROC_NOT_FOUND) return 2; } + + imports.SleepConditionVariableCS = (SleepConditionVariableCS_ptr) get_import(imports.kernel32, "SleepConditionVariableCS", &error); + if (! imports.SleepConditionVariableCS) { + if (error != ERROR_PROC_NOT_FOUND) return 3; + } + + imports.WakeConditionVariable = (WakeConditionVariable_ptr) get_import(imports.kernel32, "WakeConditionVariable", &error); + if (! imports.WakeConditionVariable) { + if (error != ERROR_PROC_NOT_FOUND) return 4; + } } else if (error != ERROR_MOD_NOT_FOUND) return 1;