Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
Diff: xlogging.c
- Revision:
- 48:81866008bba4
- Parent:
- 45:1119d0f2c4d8
diff -r e59b74c745bc -r 81866008bba4 xlogging.c --- a/xlogging.c Thu Jul 12 18:10:56 2018 -0700 +++ b/xlogging.c Tue Sep 11 11:15:08 2018 -0700 @@ -6,6 +6,10 @@ #ifndef NO_LOGGING +#ifdef WIN32 +#include "windows.h" +#endif // WIN32 + #ifdef WINCE #include <stdarg.h> @@ -38,7 +42,7 @@ (void)printf("\r\n"); } } -#endif +#endif // WINCE LOGGER_LOG global_log_function = consolelogger_log; @@ -134,4 +138,49 @@ } } -#endif +#ifdef WIN32 + +#ifdef WINCE +void xlogging_LogErrorWinHTTPWithGetLastErrorAsStringFormatter(int errorMessageID) +{ + (void)errorMessageID; +} +#else // WINCE +void xlogging_LogErrorWinHTTPWithGetLastErrorAsStringFormatter(int errorMessageID) +{ + char messageBuffer[MESSAGE_BUFFER_SIZE]; + if (errorMessageID == 0) + { + LogError("GetLastError() returned 0. Make sure you are calling this right after the code that failed. "); + } + else + { + int size = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, + GetModuleHandle("WinHttp"), errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); + if (size == 0) + { + size = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); + if (size == 0) + { + LogError("GetLastError Code: %d. ", errorMessageID); + } + else + { + LogError("GetLastError: %s.", messageBuffer); + } + } + else + { + LogError("GetLastError: %s.", messageBuffer); + } + } +} +#endif // WINCE + +#endif // WIN32 + + +#endif // NO_LOGGING + + +