#pragma message 和 outputdebugstr

接触新项目的时候发现一个很奇怪的情况,输出栏里竟然有除了文件名之外的文字

搜索发现,原来是下面这行代码的功劳

#pragma message("需要处理xxx的功能")

#pragma message(messagestring)是在编译期间,将文字串(messagestring)发送到标准输出窗口。

#pragma message在编译时报告和显示信息
outputdebugstr 在运行时显示信息 【这个试过没成功,有时间再看】

messagestring 参数可以将文字串常量扩展成一个宏,从而可以显示任何形式的字符串。

#pragma message( "Compiling " __FILE__ ) 

这样做是很方便了,但是还有局限。在标准输出窗口中可以看见#pragma message的输出信息,但是鼠标点右键弹出的上下文菜单中“Go to Error/Tag”菜单项是置灰的,不可用。

下面继续扩展,激活上下文菜单中“Go to Error/Tag”,从而定位到相应的代码行

定义头文件head.h

#define PTODO_LINENUMBER_TO_STRING(x) #x
#define PTODO_LINENUMBER(x) PTODO_LINENUMBER_TO_STRING(x)
#define INCLUDE_FILE_AND_LINE(string) __FILE__"(" PTODO_LINENUMBER(__LINE__) "): "string

其他文件引用head.h,使用方法如下

#pragma message( INCLUDE_FILE_AND_LINE("Compiling ") __FILE__ ) 

https://www.cnblogs.com/youxin/p/5437861.html

阅读更多

#pragma message 提示头文件被多次编译?

03-20

编译的时候rn[code=c]rn--------------------Configuration: petools - Win32 Release--------------------rnCompiling resources...rnCompiling...rnDisASM.cpprnNOTE: WINVER has been defined as 0x0500 or greater which enablesrnWindows NT 5.0 and Windows 98 features. When these headers were released,rnWindows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.rnFor this release when WINVER is defined as 0x0500 or greater, you can onlyrnbuild beta or test applications. To build a retail application,rnset WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdkrnto see if retail Windows NT 5.0 or Windows 98 headers are available.rnSee the SDK release notes for more information.rnExportDlg.cpprnFlcDlg.cpprnImportDlg.cpprnPEFile.cpprnpetools.cpprnNOTE: WINVER has been defined as 0x0500 or greater which enablesrnWindows NT 5.0 and Windows 98 features. When these headers were released,rnWindows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.rnFor this release when WINVER is defined as 0x0500 or greater, you can onlyrnbuild beta or test applications. To build a retail application,rnset WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdkrnto see if retail Windows NT 5.0 or Windows 98 headers are available.rnSee the SDK release notes for more information.rnpetoolsdlg.cpprnProesDlg.cpprn[/code]rnrn[color=#FF0000]搜索了下在windows.h中这样定义的[/color]rn[code=c]rnrn#if(WINVER >= 0x0500)rn#pragma message ("")rn#pragma message ("NOTE: WINVER has been defined as 0x0500 or greater which enables")rn#pragma message ("Windows NT 5.0 and Windows 98 features. When these headers were released,")rn#pragma message ("Windows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.")rn#pragma message ("")rn#pragma message ("For this release when WINVER is defined as 0x0500 or greater, you can only")rn#pragma message ("build beta or test applications. To build a retail application,")rn#pragma message ("set WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdk")rn#pragma message ("to see if retail Windows NT 5.0 or Windows 98 headers are available.")rn#pragma message ("")rn#pragma message ("See the SDK release notes for more information.")rn#pragma message ("")rn#endif[/code]rnrn我stdafx.h中定义了WINVER 0x0500. 似乎这不是问题的原因.rnwindows.h明明有#ifndef 这种防止多次编译, 为何build提示中还会出现两遍? 感谢.

没有更多推荐了,返回首页