I think it should be noted that instead of doing something like:
TestWPPLog(Error,“%s”,FUNCTION);
A better approach would be to do:
TestWPPLog(Error,“%!FUNC!”);
This way function name becomes part of the annotation in the PDB and is not a string in the executable. It also results in smaller logs. Here is a list of build in variables which can be used inside WPP messages. You can also display them by configuring TRACE_FORMAT_PREFIX.
Thanks,
Alex
%!FILE!
Displays the name of the source file from which the trace message was generated. This variable can also be used in the trace message prefix.
%!FLAGS!
Displays the value of the trace flags that enables the trace message. This variable can also be used in the trace message prefix.
%!FUNC!
Displays the function that generated the trace message. This variable can also be used in the trace message prefix.
%!LEVEL!
Displays the name of the trace level that enables the trace message. This variable can also be used in the trace message prefix.
%!LINE!
Displays line number of the line in the code that generated the trace prefix. This variable can also be used in the trace message prefix.
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Pavel A.
Sent: Wednesday, July 29, 2009 9:36 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] wpp at application layer and use of macros
Pavel A. wrote:
… I’ll repost this sample as it works for me, in a
separate message.
Here it goes:
------------- SOURCES -----------
TARGETNAME=testWPP
TARGETTYPE=PROGRAM
TARGETPATH=obj
UMENTRY=wmain
UMTYPE=console
TARGETLIBS=\
$(SDK_LIB_PATH)\ntdll.lib \
$(SDK_LIB_PATH)\kernel32.lib
INCLUDES=$(DDK_INC_PATH);
USE_MSVCRT=1
USE_NATIVE_EH=ASYNC
USE_STL=1
STL_VER=70
BUFFER_OVERFLOW_CHECKS=NTDLL
MSC_WARNING_LEVEL=/W3 /WX
C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE
SOURCES=testWPP.cpp
RUN_WPP= $(SOURCES) -scan:trace.h
_NT_TARGET_VERSION = $(_NT_TARGET_VERSION_WINXP)
------------------ trace.h -----------------------
#ifndef trace_h
#define trace_h
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(TestWPPGuid,(11223344, AAAA, BBBB, CCCC, \
DDFFFF112233), \
WPP_DEFINE_BIT(MY_ERROR) \
WPP_DEFINE_BIT(MY_WARN) \
WPP_DEFINE_BIT(MY_NOISE))
// begin_wpp config
//
// FUNC TestWPPLog(LEVEL,MSG,…);
//
// end_wpp
#endif /* trace_h */
------------------------ testwpp.cpp ----------------------
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <strsafe.h>
#include <memory.h>
#include “trace.h”
//Following is needed because of some mess in levels vs. flags +pa
#define Verbose MY_NOISE //defined in trace.h
#define Error MY_ERROR
#if 1 //+pa enable debug of the wpp stuff. see the .tmh for details.
// This allows to duplicate traces (to ODS, dbgprint…) :
#define WPP_DEBUG printf(“\n”),printf
// This enables internal debug spew of wpp:
#define WppDebug(a,b) printf(“\n”),printf b
#endif // enable wpp debug
#include “testWPP.tmh” // file created by WPP
class TestClass {
private:
BYTE Array[256];
public:
TestClass();
virtual ~TestClass();
};
TestClass::TestClass(){
TestWPPLog(Verbose,“%s”, FUNCTION );
}
TestClass::~TestClass(){
TestWPPLog(Error,“%s”, FUNCTION );
}
int __cdecl wmain( int argc, WCHAR **argv)
{
#ifdef WppDebug
printf(“debug messages from WPP will be printed\n”);
#endif
#ifdef WPP_DEBUG
printf(“traces will be echoed to printf\n”);
#endif
WPP_INIT_TRACING( L"UmWppTest" );
TestWPPLog(Verbose,“WPP test - begin log”);
TestClass * p = new TestClass;
delete p;
TestWPPLog(Error,“WPP test - end log”);
WPP_CLEANUP();
return 0;
}
----------------- end------------------
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</memory.h></strsafe.h></stdlib.h></stdio.h></windows.h>