Hi There,
I am trying to make some of the logging in the driver little more consistent and aligned. I am trying to write macros like these:-
#define RETURN_IF_NTSTS_FAILED(_status, _msg_,...) \
{ \
if (!NT_SUCCESS(_status)) { \
CHAR buffer[1024]; \
RtlStringCchPrintfA(buffer, (size_t)1024, _msg_, __VA_ARGS__); \
TraceLoggingWrite(g_hMcrTraceLoggingProvider, \
"ERROR: ", \
TraceLoggingLevel(TRACE_LEVEL_ERROR), \
TraceLoggingString(buffer, "ErrorMsg:"), \
TraceLoggingNTStatus(_status, "Status"), \
TraceLoggingString(__FUNCTION__, "Function: "), \
TraceLoggingUInt32(__LINE__, "Line: ")); \
FUNC_EXIT(); \
return _status; \
} \
}
#define STRINGIFY(x) #x
#define RETURN_ON_COND_MSG(_cond_, _msg_, ...) \
do { \
if ((_cond_)) { \
CHAR buffer[1024]; \
RtlStringCchPrintfA(buffer, (size_t)1024, _msg_, __VA_ARGS__); \
TraceLoggingWrite(g_hMcrTraceLoggingProvider, \
"ERROR: ", \
TraceLoggingLevel(TRACE_LEVEL_ERROR), \
TraceLoggingString(STRINGIFY(_cond_), "Return On Condition: "), \
TraceLoggingString(buffer, "ErrorMsg:"), \
TraceLoggingString(__FUNCTION__, "Function: "), \
TraceLoggingUInt32(__LINE__, "Line: ")); \
return; \
} \
} while (0)
When I use these, my driver just misbehaves randomly and results in a BSOD. These are simple macros and I am not sure what am I missing here. I am pretty sure something really basic.
Any pointers appreciated.
Thanks
Aj