subject_23314.htm
来自「一些关于vc的问答」· HTM 代码 · 共 66 行
HTM
66 行
<p>
序号:23314 发表者:asdfgh 发表日期:2002-12-03 10:40:29
<br>主题:一个编译问题
<br>内容:我编译一个msdn标准程序的时候有这样的错误Compiling...<BR>contest.cpp<BR>c:\program files\microsoft visual studio\vc98\include\winnt.h(152) : error C2146: syntax error : missing ';' before identifier 'WCHAR'<BR>c:\program files\microsoft visual studio\vc98\include\winnt.h(152) : fatal error C1004: unexpected end of file found<BR>Error executing cl.exe.<BR><BR>contest.obj - 2 error(s), 0 warning(s)<BR><BR>请问这是哪方面的问题?<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:擎天柱 回复日期:2002-12-03 10:57:50
<br>内容:应该是有关UNICODE的问题,查看一下是否包含UNICODE的宏定义。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:asdfgh 回复日期:2002-12-03 11:03:28
<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-12-03 11:09:00
<br>内容:<BR>在contest.cpp上加上<BR><BR>#include "stdafx.h" <BR>#include <windows.h> <BR>#include <TCHAR.h>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:asdfgh 回复日期:2002-12-03 11:23:55
<br>内容:加上之后是这样的错误<BR><BR>Deleting intermediate files and output files for project 'contest - Win32 Debug'.<BR>--------------------Configuration: contest - Win32 Debug--------------------<BR>Compiling...<BR>StdAfx.cpp<BR>Compiling...<BR>contest.cpp<BR>c:\program files\microsoft visual studio\vc98\include\winnt.h(152) : error C2501: 'PCWCH' : missing storage-class or type specifiers<BR>F:\CApp\contest\contest.cpp(15) : error C2065: 'BUFFER_SIZE' : undeclared identifier<BR>F:\CApp\contest\contest.cpp(15) : error C2057: expected constant expression<BR>F:\CApp\contest\contest.cpp(15) : error C2466: cannot allocate an array of constant size 0<BR>F:\CApp\contest\contest.cpp(15) : error C2133: 'bBuffer' : unknown size<BR>F:\CApp\contest\contest.cpp(23) : error C2065: 'ErrorExit' : undeclared identifier<BR>F:\CApp\contest\contest.cpp(42) : fatal error C1903: unable to recover from previous error(s); stopping compilation<BR>Error executing cl.exe.<BR><BR>contest.exe - 7 error(s), 0 warning(s)<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>
回复者:asdfgh 回复日期:2002-12-03 11:27:21
<br>内容:现在contest.cpp的头文件如下:<BR><BR><BR>#include "stdafx.h"<BR>#include <TCHAR.h><BR>#include <windows.h> <BR>#include <winnt.h><BR><BR>不知道是否有问题?<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-12-03 11:42:12
<br>内容:<BR>改为<BR><BR>#include "stdafx.h"<BR>#include <windows.h> <BR>#include <winnt.h><BR>#include <TCHAR.h><BR><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>
回复者:asdfgh 回复日期:2002-12-03 11:52:30
<br>内容:现在是这样的错误<BR>Compiling...<BR>StdAfx.cpp<BR>Compiling...<BR>contest.cpp<BR>F:\CApp\contest\contest.cpp(16) : error C2065: 'BUFFER_SIZE' : undeclared identifier<BR>F:\CApp\contest\contest.cpp(16) : error C2057: expected constant expression<BR>F:\CApp\contest\contest.cpp(16) : error C2466: cannot allocate an array of constant size 0<BR>F:\CApp\contest\contest.cpp(16) : error C2133: 'bBuffer' : unknown size<BR>F:\CApp\contest\contest.cpp(24) : error C2065: 'ErrorExit' : undeclared identifier<BR>F:\CApp\contest\contest.cpp(43) : fatal error C1903: unable to recover from previous error(s); stopping compilation<BR>Error executing cl.exe.<BR><BR><BR>我的代码如下:<BR>------------------------------------------------------------------------------<BR>// contest.cpp : Defines the entry point for the console application.<BR>//<BR>#include "stdafx.h"<BR>#include <windows.h> <BR>#include <winnt.h><BR>#include <TCHAR.h><BR><BR><BR>//#include "eventlog.h"<BR><BR>int main(int argc, char* argv[])<BR>{<BR> printf("Hello World!\n");<BR> HANDLE h;<BR> EVENTLOGRECORD *pevlr; <BR> BYTE bBuffer[BUFFER_SIZE]; <BR> DWORD dwRead, dwNeeded, cRecords, dwThisRecord; <BR> <BR> // Open the Application event log. <BR> <BR> h = OpenEventLog( NULL, // use local computer<BR> "Application"); // source name<BR> if (h == NULL) <BR> ErrorExit("Could not open the Application event log."); <BR> <BR> pevlr = (EVENTLOGRECORD *) &bBuffer; <BR> <BR> // Get the record number of the oldest event log record.<BR><BR> GetOldestEventLogRecord(h, &dwThisRecord);<BR><BR> // Opening the event log positions the file pointer for this <BR> // handle at the beginning of the log. Read the event log records <BR> // sequentially until the last record has been read. <BR> <BR> while (ReadEventLog(h, // event log handle <BR> EVENTLOG_FORWARDS_READ | // reads forward <BR> EVENTLOG_SEQUENTIAL_READ, // sequential read <BR> 0, // ignored for sequential reads <BR> pevlr, // pointer to buffer <BR> BUFFER_SIZE, // size of buffer <BR> &dwRead, // number of bytes read <BR> &dwNeeded)) // bytes in next record <BR> {<BR> while (dwRead > 0) <BR> { <BR> // Print the record number, event identifier, type, <BR> // and source name. <BR> <BR> printf("%02d Event ID: 0x%08X ", <BR> dwThisRecord++, pevlr->EventID); <BR> printf("EventType: %d Source: %s\n", <BR> pevlr->EventType, (LPSTR) ((LPBYTE) pevlr + <BR> sizeof(EVENTLOGRECORD))); <BR> <BR> dwRead -= pevlr->Length; <BR> pevlr = (EVENTLOGRECORD *) <BR> ((LPBYTE) pevlr + pevlr->Length); <BR> } <BR> <BR> pevlr = (EVENTLOGRECORD *) &bBuffer; <BR> } <BR> <BR> CloseEventLog(h); <BR> printf("That's All!\n");<BR><BR>// eventlog test=new eventlog();<BR> return 0;<BR>}<BR><BR>-------------------------------------------------------------------------------<BR>cut here<BR><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-12-03 23:42:31
<br>内容:天啊,<BR>BUFFER_SIZE和ErrorExit都没定义啊
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:白云 回复日期:2002-12-04 08:49:47
<br>内容:你没有定义BUFFER_SIZE和ErrorExit<BR>另外头文件也不大对<BR>编译成功的源码:<BR>#include <stdio.h><BR>#include <winnt.h><BR>#include <TCHAR.h><BR><BR><BR>//#include "eventlog.h"<BR>#define BUFFER_SIZE 1024<BR>#define ErrorExit(x) printf(x)<BR>int main(int argc, char* argv[])<BR>{<BR> printf("Hello World!\n");<BR> HANDLE h;<BR> EVENTLOGRECORD *pevlr; <BR> BYTE bBuffer[BUFFER_SIZE]; <BR> DWORD dwRead, dwNeeded, cRecords, dwThisRecord; <BR><BR> // Open the Application event log. <BR><BR> h = OpenEventLog( NULL, // use local computer<BR> "Application"); // source name<BR> if (h == NULL) <BR> ErrorExit("Could not open the Application event log."); <BR><BR> pevlr = (EVENTLOGRECORD *) &bBuffer; <BR><BR> // Get the record number of the oldest event log record.<BR><BR> GetOldestEventLogRecord(h, &dwThisRecord);<BR><BR> // Opening the event log positions the file pointer for this <BR> // handle at the beginning of the log. Read the event log records <BR> // sequentially until the last record has been read. <BR><BR> while (ReadEventLog(h, // event log handle <BR> EVENTLOG_FORWARDS_READ | // reads forward <BR> EVENTLOG_SEQUENTIAL_READ, // sequential read <BR> 0, // ignored for sequential reads <BR> pevlr, // pointer to buffer <BR> BUFFER_SIZE, // size of buffer <BR> &dwRead, // number of bytes read <BR> &dwNeeded)) // bytes in next record <BR> {<BR> while (dwRead > 0) <BR> { <BR> // Print the record number, event identifier, type, <BR> // and source name. <BR><BR> printf("%02d Event ID: 0x%08X ", <BR> dwThisRecord++, pevlr->EventID); <BR> printf("EventType: %d Source: %s\n", <BR> pevlr->EventType, (LPSTR) ((LPBYTE) pevlr + <BR> sizeof(EVENTLOGRECORD))); <BR><BR> dwRead -= pevlr->Length; <BR> pevlr = (EVENTLOGRECORD *) <BR> ((LPBYTE) pevlr + pevlr->Length); <BR> } <BR><BR> pevlr = (EVENTLOGRECORD *) &bBuffer; <BR> } <BR><BR> CloseEventLog(h); <BR> printf("That's All!\n");<BR><BR>// eventlog test=new eventlog();<BR> return 0;<BR>}<BR><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>
回复者:asdfgh 回复日期:2002-12-04 09:21:59
<br>内容:thanks all 谢谢大家,我被前面的错误弄晕了,所以........sigh! 多谢大家,以后在骚扰大家
<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 + -
显示快捷键?