From: Iain Patterson Date: Sat, 21 Dec 2013 16:05:18 +0000 (+0000) Subject: Fixed Unicode display of GetProcAddress() errors. X-Git-Tag: v2.22~125 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=d3b4f286fa65c5a8881d595038505229e467bf49;p=nssm.git Fixed Unicode display of GetProcAddress() errors. GetProcAddress() takes char *name as an argument but we were trying to print TCHAR *name when logging that we couldn't find the function pointer. --- diff --git a/imports.cpp b/imports.cpp index 947b885..9ffd486 100644 --- a/imports.cpp +++ b/imports.cpp @@ -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), 0); + 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, function, _TRUNCATE); +#else + function_name = 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;