偶遇“winver”

    今天自己照书编写了《windows 程序设计》第四章的sysmets1程序,结果出错如下:

sysmets1/sysmets1.h(147) : error C2065: 'SM_MOUSEWHEELPRESENT' : undeclared identifier
sysmets1/sysmets1.h(147) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(147) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'unsigned short [21]'
sysmets1/sysmets1.h(149) : error C2065: 'SM_XVIRTUALSCREEN' : undeclared identifier
sysmets1/sysmets1.h(149) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(150) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'unsigned short [24]'
sysmets1/sysmets1.h(151) : error C2065: 'SM_YVIRTUALSCREEN' : undeclared identifier
sysmets1/sysmets1.h(151) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(153) : error C2065: 'SM_CXVIRTUALSCREEN' : undeclared identifier
sysmets1/sysmets1.h(153) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(153) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'unsigned short [19]'
sysmets1/sysmets1.h(155) : error C2065: 'SM_CYVIRTUALSCREEN' : undeclared identifier
sysmets1/sysmets1.h(155) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(156) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'unsigned short [22]'
sysmets1/sysmets1.h(157) : error C2065: 'SM_CMONITORS' : undeclared identifier
sysmets1/sysmets1.h(157) : error C2099: initializer is not a constant
sysmets1/sysmets1.h(159) : error C2065: 'SM_SAMEDISPLAYFORMAT' : undeclared identifier
sysmets1/sysmets1.h(159) : error C2099: initializer is not a constant

sysmets1/sysmets1.h(159) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'unsigned short [21]'
Error executing cl.exe.
Creating browse info file...

SYSMETS1.exe - 14 error(s), 5 warning(s)

 

解决办法:

因为各个window版本所能使用的常量不一样,所以在xp环境下,必须在sysmets1.c文件最开始处加入一句:
#define WINVER 0x0501

以下是windows其他版本号:
windows server 2003
winver>=0x0502

windows xp
winver>=0x0501

windows 2000
winver>=0x0500

windows nt 4.0
winver>=0x0400

windows me
winver>=0x0500

windows 98
winver>=0x0410

windows 95
winver>=0x0400

winver是检查Windows版本的命令,开始->运行->winver,可以看出你当前的Windows版本信息。

 

 

你可能感兴趣的:(c,windows,server,XP)