How to fix TraceLogging build errors

This topic describes some common build errors and how to resolve them.

Case 1: 'DECLSPEC_SAFEBUFFERS' errors

Build Error (snippet):

1>traceloggingprovider.h(1592): error C2146: syntax error : missing ';' before identifier 'TLG_STATUS'
1>traceloggingprovider.h(1592): error C2433: 'DECLSPEC_SAFEBUFFERS' : 'inline' not permitted on data declarations
1>traceloggingprovider.h(1592): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Fix:
Include windows.h before including TraceLoggingProvider.h in your source file.

Case 2: TraceLogging in Modern C++ Apps

Build Error (snippet):
After copying the TraceLogging header files into your build environment and adding this line:

TraceLoggingRegisterByGuid(g_3DBuilderTraceProvider, &s_3DBuilderTraceProviderGuid);

You got this linker error:

Error 2 error LNK2001: unresolved external symbol __imp__EventSetInformation@20 
        E:\TFS\Main\PrintPreviewR5\Viewers\PrintPreview\App.xaml.obj    PrintPreview
Error 3 error LNK2001: unresolved external symbol __imp__EventRegister@16       
        E:\TFS\Main\PrintPreviewR5\Viewers\PrintPreview\App.xaml.obj    PrintPreview

Fix:
UWP apps need to link against advapi32.lib to resolve this reference issue.

Case 3: Phone Builds

Build Error (snippet):
When compiling the file dictationuimodel.cpp, you get the error:

traceloggingprovider.h(1592) : error C2146: syntax error : missing ';' before identifier 'TLG_STATUS'
traceloggingprovider.h(1592) : error C2433: 'DECLSPEC_SAFEBUFFERS' : 'inline' not permitted on data declarations

Fix:
See Case#1. It is likely that your SDK does not define the macro DECLSPEC_SAFEBUFFERS. Up-to-date SDKs have a definition for this macro. If your SDK does not define this macro, you will need to provide your own definition. DECLSPEC_SAFEBUFFERS is defined in winnt.h, which should be included by windows.h. Also, until the public release of the Windows 10 SDK you may need to define the Telemetry keyword:

#ifndef WINEVENT_KEYWORD_TELEMETRY 
#define WINEVENT_KEYWORD_TELEMETRY  0x2000000000000
#endif