将驱动程序移植到Win7时出现错误C2054 [英] Error C2054 while porting driver to Win7

查看:125
本文介绍了将驱动程序移植到Win7时出现错误C2054的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用WDK 7600.163385.1将旧驱动程序(用C语言编写)从Win2k移植到Win7时遇到以下错误:

code.c(x):错误C2054:预期``(''跟随``i''

代码段:

I am running into following error while trying to port an old driver (written in C) from Win2k to Win7 using WDK 7600.163385.1:

code.c(x) : error C2054: expected ''('' to follow ''i''

Code snippet:

static NTSTATUS
MyCreateDevice(
	IN DEVICE_TYPE DeviceType,
	IN PDRIVER_OBJECT pDriverObject,
	OUT PDEVICE_OBJECT *ppDevObj
	);



根据我到目前为止发现的信息,这可能是由于缺少键盘输入"IN"的定义,但是我不知道在哪里定义.另外,如果我将.c文件重命名为.cpp文件,但由于两个原因,我不想这样做,则错误消失了:
1.它是一个内核级模块,MS不支持cpp. 2.我将需要对我的代码进行其他更改,因为其他一些功能仅与C程序兼容

任何帮助和指导,我将不胜感激.

谢谢
Piyush



Based on the information I have found so far, it may be due to missing definition of keywork ''IN'', but I do not know where is it defined. Also, the error goes away if I rename .c file to .cpp file but I do not want to do so for 2 reasons:
1. it is a kernel level module for which cpp is unsupported by MS
2. I will need to make additional changes to my code since some other featues are compatible with only C program

I would appreciate any help and guidance.

Thanks
Piyush

推荐答案

1.通常将IN和OUT定义为空:

1. IN and OUT are usually define as nothing:

#define IN
#define OUT



(C中没有可区分输入和输出参数的关键字.)

2.尝试将/P添加到编译器命令行中("Visual Studio属性"页中"C/C ++,预处理器"下的生成预处理文件"选项.)

这样会将预处理器输出保存到单独的文件中,然后您可以检查该文件以查看正在使用的预处理器定义.

(我怀疑NTSTATUS以某种方式定义为"i",这是最可能获得该错误消息的方式.)

3.使用C ++编译器编译C代码并将其用于内核模式驱动程序应该没有问题.如果您基本上只是编写C,就不会遇到C ++的麻烦.如果您使用的不是C的C ++的高级"功能并且不了解编译器的实现方式,则可能会遇到麻烦.这些功能.但是,如果您愿意,可能会导致使用C出现相同的问题(只是当您在C中编写相同的内容时,它看起来是如此复杂,以至于您知道这可能是个坏消息.)请参阅:http://msdn.microsoft.com/en-us/windows/hardware/gg487420 [ ^ ]

但是,我不只是从C切换到CPP而不了解问题所在.当问题以魔术般的方式消失时,他们有回来的习惯,以后再咬你...



(there is no keyword in C that distinguishes input and output parameters).

2. Try adding /P to your compiler command line ("Generate Preprocessed File" option in Visual Studio Properties page under C/C++, Preprocessor".)

That will save the preprocessor output to a separate file which you can then inspect to see what preprocessor definitions are being used.

(I suspect NTSTATUS is somehow defined as ''i'' -- that''s the most likely way you would get that error message.)

3. There shouldn''t be a problem with compiling C code with the C++ compiler and using it for a kernel mode driver. You won''t get in trouble using C++ if you are basically just writing C. You might get into trouble if you are using "advanced" features of C++ that aren''t C and don''t understand how the compiler is implementing those features. But you can cause the same problems using C if you want to (it''s just that when you write the same thing in C it looks so complex that you know it''s probably bad news.) See: http://msdn.microsoft.com/en-us/windows/hardware/gg487420[^]

However, I wouldn''t just switch from C to CPP without understanding what the problem is. When problems just magically go away they have a habit of coming back and biting you later...


这篇关于将驱动程序移植到Win7时出现错误C2054的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆