您的位置:首页 > 其它

KMDF工程新增source文件出现的"TraceEvents未定义”编译错误

2016-04-26 14:40 627 查看
问题引入:在windows驱动开发过程中,我们一般会用VS2015+WDK10,新建一个KMDF工程(非empty)。该过程可参考我的另一篇博客:点击打开链接。这个工程新建好了,并能编译通过,但有时我们需要在该工程中新增source文件。通过在VS中“添加现有项"或”新增加项“的方式添加一个或几个新的源文件到工程中。然后再编译,会报错”error
C4013: “TraceEvents”未定义;假设外部返回 int“等与”TraceEvents“相关的错误。

参考微软的官方文档:WPP。TraceEvents隶属于WPP,是WDF中的日志打印相关的宏。如下:

The trace message header (.tmh) file must be included in a source file

before any WPP macro calls and after defining a WPP_CONTROL_GUIDS

macro (defined in toaster.h). During the compilation, WPP scans the source

files for DoTraceMessage() calls and builds a .tmh file which stores a unique

data GUID for each message, the text resource string for each message,

and the data types of the variables passed in for each message. This file

is automatically generated by the WPP preprocessor.

以上这段注释,说明:在使用TraceEvents之前,需要先包含”.tmh“文件。该文件由WPP预处理器生成。

参考我的另一篇博客:点击打开链接

但是,这次出现的这个编译错误是在包含了改文件之后,还存在。

解决办法:

右键新添加的source文件,添加如下内容:



注:

从前面所说的微软官方文档可以知道:


Step 5: Instrument the driver code to generate trace messages at appropriate points

You can use any trace message function you choose, provided the trace message function, the trace flags, and levels are defined appropriately. The default trace message function is the DoTraceMessage macro.
You can add this macro to your code to write messages to the log file. The following table lists some of the predefined trace message functions and the debug print functions you can use to create trace messages.
默认的trace msg生成函数是”DoTraceMessage“,它没有信息分级和分标志。要使用TraceEvents,需要按上述的方式自行指定,否则编译出错。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: