WPP has its own preprocessor that runs before the C/C++ one and so you can't wrap the trace statements in macros (annoying but been a known issue since the beginning).
The backwards way to do this is to wrap the trace message call in WPP PRE and POST macros that do what you want. It's kind of painful to get right the first time but once you have it it's handy (e.g. we do this to log failed ASSERTs into the WPP Recorder in the release build). Your above behavior could be implemented with something like this:
(That also might require some additional massaging and could possibly be simplified, I just threw it together for an example. WPP is always a bit finicky...)
@Scott_Noone_OSR , thanks. But I'm still getting that same error. And yes. You bet, WPP is a finicky beast.
Let me show what I'm doing.
First off, I added your exact same declarations/definitions into the trace.h file.
Then the definitions of WPP_FLAG_PRE and WPP_FLAG_POST went into the .h file for the .cpp file where I was intending to use them. (But then I also tried to place them into trace.h. It didn't help.)
What doesn't work? It doesn't compile? Or it compiles but you don't see the expected trace? Or something else?
Here's a diff patch that adds what I put here into the tracedrv sample. I didn't run it but it compiles and seems to emit the right code based on the assembly. (As I style thing I don't like the WPP macro raising a status, but that's not the question at the moment...)
@Scott_Noone_OSR sorry, I got so frustrated with this WPP BS ... so I just dropped it.
Now that I calmed down and decided to give it a second try. I'm realizing that I'm probably not doing something obvious. To show it, I created a default KMDF project in VS 2022 and added your suggestions.
I'm still getting these errors when I try to compile it:
Driver.c(69,5): error C4013: 'WPP_RECORDER_FLAG_FILTER' undefined; assuming extern returning int
Driver.c(69,5): error C2065: 'PASSIVE_ASSERTS': undeclared identifier
Driver.c(69,5): error C4013: 'WPP_RECORDER_FLAG_ARGS' undefined; assuming extern returning int
Driver.c(69,5): warning C4022: 'WPP_RECORDER_SF_': pointer mismatch for actual parameter 1
Driver.c(69,5): warning C4047: 'function': 'ULONG' differs in levels of indirection from 'const GUID *'
Driver.c(69,5): warning C4024: 'WPP_RECORDER_SF_': different types for formal and actual parameter 3
Driver.c(69,5): error C2198: 'WPP_RECORDER_SF_': too few arguments for call
I made a copy of that project here. Can you please take a look? There are just a few modifications there.
Everything WPP related is tediously difficult to get right. My suggestion is to examine the tmh file to see exactly what is being emitted by the WPP preprocessor.