subject_19259.htm

来自「一些关于vc的问答」· HTM 代码 · 共 36 行

HTM
36
字号
<p>
序号:19259 发表者:小小申 发表日期:2002-10-27 11:45:19
<br>主题:请问#ifndef#define#endif怎么用啊?
<br>内容:看MSDN都看不懂,请问#ifndef#define#endif怎么用啊?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:木子 回复日期:2002-10-27 13:27:49
<br>内容:这些是编译命令,决定程序执不执行其中包含的命令<BR>#ifdef STDENT<BR>...<BR>#endif<BR>如果在#ifdef之前声明过STUDENT,则执行其中的命令,否则,不执行<BR>#ifndef STUDENT<BR>...<BR>#endif<BR>如果在#ifndef之前没有声明过STUDENT,则执行其中的命令,否则,不执行
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小小申 回复日期:2002-10-27 13:57:06
<br>内容:#ifndef STDINC_H//STDINC_H这代表当前文件,你的意思是为减少重复include此头文件<BR>#define STDINC_H//其实我也有此理解、再看看后面的<BR><BR><BR>//<BR>// Visual C++ has cannot manage debug infor for symbols greater than 255<BR>// characters. However, it is easy to have symbol lengths greater than 255 <BR>// when using the STL. Therefore, I'm disabling this warning here.<BR>//<BR>#pragma warning(disable: 4786)<BR><BR><BR>//<BR>// This is, after all, a book about DCOM...<BR>//<BR>#define _WIN32_DCOM<BR><BR><BR>//<BR>// If either of the ATL flags are set, then we're using ATL (duh!)<BR>//<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; #error Please specify USE_ATL_INPROC or USE_ATL_LOCAL to indicate your project uses ATL<BR>#endif<BR>#ifdef USE_ATL_INPROC<BR>&nbsp;&nbsp; #define USE_ATL<BR>#endif<BR>#ifdef USE_ATL_LOCAL<BR>&nbsp;&nbsp; #define USE_ATL<BR>#endif<BR><BR><BR>//<BR>// Are console operations available?<BR>//下面这段怎么理解、这里跟include没关了吧<BR>//USE_MFC代表什么啊、<BR>//也没看到以后的文件使用此家伙啊<BR>//他的意思使用MFC就象输出DOS命令行的,<BR>//使用ATL也一样的<BR>#ifdef USE_MFC<BR>&nbsp;&nbsp; #define NO_CONSOLE<BR>#endif<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; // Not strictly true, of course<BR>&nbsp;&nbsp; #define NO_CONSOLE<BR>#endif<BR><BR><BR>//<BR>// We ARE using MFC<BR>//<BR>#ifdef USE_MFC<BR>&nbsp;&nbsp; #include &lt;afxwin.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxcmn.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxext.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxdisp.h&gt;<BR>&nbsp;&nbsp; #include &lt;cguid.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxctl.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxtempl.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxdlgs.h&gt;<BR><BR><BR>//<BR>// We are not using MFC<BR>//<BR>#else USE_MFC<BR><BR>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; // Get basic Windows stuff<BR>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; #define STRICT<BR>&nbsp;&nbsp; #ifndef NO_INC_OLE2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#define INC_OLE2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;windows.h&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;ole2.h&gt;<BR>&nbsp;&nbsp; #else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;windows.h&gt;<BR>&nbsp;&nbsp; #endif<BR>&nbsp;&nbsp; #include &lt;cguid.h&gt;<BR><BR>#endif<BR><BR><BR>//<BR>// We ARE using ATL<BR>//<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; // #define _WIN32_WINNT 0x0400<BR>&nbsp;&nbsp; #define _ATL_APARTMENT_THREADED<BR>&nbsp;&nbsp; #include &lt;atlbase.h&gt;<BR><BR>&nbsp;&nbsp; // What is our module class? This is a utility header, it should<BR>&nbsp;&nbsp; // be found in the same diredctory as this file<BR>&nbsp;&nbsp; #include "atlmod.h"<BR><BR>&nbsp;&nbsp; #include &lt;atlcom.h&gt;<BR>#endif<BR><BR><BR>// Some helpful type aliases<BR>typedef PVOID*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PPVOID;<BR>typedef unsigned char&nbsp;&nbsp; UCHAR;<BR>typedef unsigned char*&nbsp;&nbsp;PUCHAR;<BR>typedef unsigned short&nbsp;&nbsp;USHORT;<BR>typedef unsigned short* PUSHORT;<BR>typedef unsigned long&nbsp;&nbsp; ULONG;<BR>typedef unsigned long*&nbsp;&nbsp;PULONG;<BR>typedef BSTR*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PBSTR;<BR><BR>#endif
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小小申 回复日期:2002-10-27 13:58:46
<br>内容:讲得还是不是很清楚啊
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小小申 回复日期:2002-10-27 17:47:09
<br>内容:<BR>#ifdef STDENT<BR>...<BR>#endif<BR>如果在#ifdef之前声明过STUDENT,则执行其中的命令,否则,不执行<BR><BR>在我贴的头文件中,以后的其他文件都没用到USE_MFC和USE_ATL<BR>我怎么知道是USE_MFC还是USE_ATL
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小小申 回复日期:2002-10-27 23:24:22
<br>内容:对了,那个头文件是一个DCOM的例子里的<BR>#ifndef STDINC_H//<BR>#define STDINC_H//<BR><BR>//<BR>// Visual C++ has cannot manage debug infor for symbols greater than 255<BR>// characters. However, it is easy to have symbol lengths greater than 255 <BR>// when using the STL. Therefore, I'm disabling this warning here.<BR>//<BR>#pragma warning(disable: 4786)<BR><BR><BR>//<BR>// This is, after all, a book about DCOM...<BR>//<BR>#define _WIN32_DCOM<BR><BR><BR>//<BR>// If either of the ATL flags are set, then we're using ATL (duh!)<BR>//<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; #error Please specify USE_ATL_INPROC or USE_ATL_LOCAL to indicate your project uses ATL<BR>#endif<BR>#ifdef USE_ATL_INPROC<BR>&nbsp;&nbsp; #define USE_ATL<BR>#endif<BR>#ifdef USE_ATL_LOCAL<BR>&nbsp;&nbsp; #define USE_ATL<BR>#endif<BR><BR><BR>//<BR>// Are console operations available?<BR>//#ifdef USE_MFC<BR>&nbsp;&nbsp; #define NO_CONSOLE<BR>#endif<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; // Not strictly true, of course<BR>&nbsp;&nbsp; #define NO_CONSOLE<BR>#endif<BR><BR><BR>//<BR>// We ARE using MFC<BR>//<BR>#ifdef USE_MFC<BR>&nbsp;&nbsp; #include &lt;afxwin.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxcmn.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxext.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxdisp.h&gt;<BR>&nbsp;&nbsp; #include &lt;cguid.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxctl.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxtempl.h&gt;<BR>&nbsp;&nbsp; #include &lt;afxdlgs.h&gt;<BR><BR><BR>//<BR>// We are not using MFC<BR>//<BR>#else USE_MFC<BR><BR>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; // Get basic Windows stuff<BR>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; #define STRICT<BR>&nbsp;&nbsp; #ifndef NO_INC_OLE2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#define INC_OLE2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;windows.h&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;ole2.h&gt;<BR>&nbsp;&nbsp; #else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;windows.h&gt;<BR>&nbsp;&nbsp; #endif<BR>&nbsp;&nbsp; #include &lt;cguid.h&gt;<BR><BR>#endif<BR><BR><BR>//<BR>// We ARE using ATL<BR>//<BR>#ifdef USE_ATL<BR>&nbsp;&nbsp; // #define _WIN32_WINNT 0x0400<BR>&nbsp;&nbsp; #define _ATL_APARTMENT_THREADED<BR>&nbsp;&nbsp; #include &lt;atlbase.h&gt;<BR><BR>&nbsp;&nbsp; // What is our module class? This is a utility header, it should<BR>&nbsp;&nbsp; // be found in the same diredctory as this file<BR>&nbsp;&nbsp; #include "atlmod.h"<BR><BR>&nbsp;&nbsp; #include &lt;atlcom.h&gt;<BR>#endif<BR><BR><BR>// Some helpful type aliases<BR>typedef PVOID*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PPVOID;<BR>typedef unsigned char&nbsp;&nbsp; UCHAR;<BR>typedef unsigned char*&nbsp;&nbsp;PUCHAR;<BR>typedef unsigned short&nbsp;&nbsp;USHORT;<BR>typedef unsigned short* PUSHORT;<BR>typedef unsigned long&nbsp;&nbsp; ULONG;<BR>typedef unsigned long*&nbsp;&nbsp;PULONG;<BR>typedef BSTR*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PBSTR;<BR><BR>#endif <BR><BR>我的意思<BR>我再问中间那段<BR>以后的其他文件都没出现USE_MFC和USE_ATL<BR>都没用到USE_MFC和USE_ATL<BR>我怎么知道是USE_MFC还是USE_ATL <BR><BR>还有<BR>#ifndef<BR>#define STUDENT<BR>#endif<BR><BR>STUDENT有没有值的?如果有,是不是随机值?<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?