阅读:1500回复:5
老罗的HelloWDM例程不能编译通过(求助)
老罗的HelloWDM例程不能编译通过。
出现如下错误: D:\\HELLOW~1\\HELLOW~1>build.exe -ceZ BUILD: Object root set to: ==> objchk BUILD: /i switch ignored BUILD: Compile and Link for i386 BUILD: Compiling d:\\hellow~1\\hellow~1 directory Compiling - hellowdm.c for i386 hellowdm.c(16) : error C2059: syntax error : \'string\' hellowdm.c(56) : error C2275: \'PDEVICE_EXTENSION\' : illegal use of this type as an expression hellowdm.c(56) : error C2146: syntax error : missing \';\' before identifier \'dx\' hellowdm.c(56) : error C2065: \'dx\' : undeclared identifier hellowdm.c(57) : error C2223: left of \'->fdo\' must point to struct/union hellowdm.c(60) : error C2223: left of \'->NextStackDevice\' must point to struct/union hellowdm.c(87) : error C2275: \'NTSTATUS\' : illegal use of this type as an expression hellowdm.c(87) : error C2146: syntax error : missing \';\' before identifier \'status\' hellowdm.c(87) : error C2065: \'status\' : undeclared identifier BUILD: Compile errors: not linking d:\\hellow~1\\hellow~1 directory BUILD: Done 1 file compiled - 3 Warnings - 9 Errors Tool returned code: 0 附所做的例程。 |
|
|
沙发#
发布于:2004-05-10 10:53
为了方便没时间打开附件的朋友,我将例程中的四个文件贴出来。
现将我按他的说法做的例程贴上来。 /*************************************************************** 程序名称:Hello World for WDM 文件名称:HelloWDM.h 作者:罗聪 日期:2002-8-16 ***************************************************************/ //头文件,只是声明一些函数和变量,比较简单就不多说了,请读者自行研究: #include \"wdm.h\" #ifdef __cplusplus extern \"C\" { #endif #include \"ntddk.h\" #ifdef __cplusplus } #endif typedef struct _DEVICE_EXTENSION { PDEVICE_OBJECT fdo; PDEVICE_OBJECT NextStackDevice; UNICODE_STRING ifSymLinkName; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; NTSTATUS HelloWDMAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject); NTSTATUS HelloWDMPnp(IN PDEVICE_OBJECT fdo, IN PIRP Irp); /*************************************************************** 程序名称:Hello World for WDM 文件名称:HelloWDM.cpp 作者:罗聪 日期:2002-8-16 ***************************************************************/ //一定要的头文件,声明了函数模块和变量: #include \"HelloWDM.h\" /*************************************************************** 函数名称:DriverEntry() 功能描述:WDM程序入口 ***************************************************************/ //extern \"C\"是必须的,表示“用C链接”。如果你的文件名是HelloWDM.c的话,这句可以省略。 extern \"C\" NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath) { //指定“添加设备”消息由函数“HelloWDMAddDevice()”来处理: DriverObject->DriverExtension->AddDevice = HelloWDMAddDevice; //指定“即插即用”消息由函数“HelloWDMPnp()”来处理: DriverObject->Majorfunction[IRP_MJ_PNP] = HelloWDMPnp; //返回一个NTSTATUS值STATUS_SUCCESS。几乎所有的驱动程序例程都必须返回一个NTSTATUS值,这些值在NTSTATUS.H DDK头文件中有详细的定义。 return STATUS_SUCCESS; } /*************************************************************** 函数名称:HelloWDMAddDevice() 功能描述:处理“添加设备”消息 ***************************************************************/ NTSTATUS HelloWDMAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject) { //定义一个NTSTATUS类型的返回值: NTSTATUS status; //定义一个功能设备对象(functional Device Object): PDEVICE_OBJECT fdo; //创建我们的功能设备对象,并储存到fdo中: status = IoCreateDevice( DriverObject, //驱动程序对象 sizeof(DEVICE_EXTENSION), //要求的设备扩展的大小 NULL, //设备名称,这里为NULL FILE_DEVICE_UNKNOWN, //设备的类型,在标准头文件WDM.H或NTDDK.H中列出的FILE_DEVICE_xxx值之一 0, //各种常量用OR组合在一起,指示可删除介质、只读等。 FALSE, //如果一次只有一个线程可以访问该设备,为TRUE,否则为FALSE &fdo); //返回的设备对象 //NT_SUCCESS宏用于测试IoCreateDevice内核是否成功完成。不要忘记检查对内核的所有调用是否成功。NT_ERROR宏不等同于!NT_SUCCESS,最好使用!NT_SUCCESS,因为除了错误外,它还截获警告信息。 if( !NT_SUCCESS(status)) return status; //创建一个设备扩展对象dx,用于存储指向fdo的指针: PDEVICE_EXTENSION dx = (PDEVICE_EXTENSION)fdo->DeviceExtension; dx->fdo = fdo; //用IoAttachDeviceToDeviceStack函数把HelloWDM设备挂接到设备栈: dx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject); //设置fdo的flags。有两个“位”是必须改变的,一个是必须清除DO_DEVICE_INITIALIZING标志,如果在DriverEntry例程中调用IoCreateDevice(),就不需要清除这个标志位。还有一个是必须设置DO_BUFFER_IO标志位: fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; fdo->Flags &= ~DO_DEVICE_INITIALIZING; //返回值: return STATUS_SUCCESS; } /*************************************************************** 函数名称:HelloWDMPnp() 功能描述:处理“即插即用”消息 ***************************************************************/ NTSTATUS HelloWDMPnp(IN PDEVICE_OBJECT fdo, IN PIRP Irp) { //创建一个设备扩展对象dx,用于存储指向fdo的指针: PDEVICE_EXTENSION dx=(PDEVICE_EXTENSION)fdo->DeviceExtension; //首先要通过函数IoGetCurrentIrpStackLocation()得到当前的IRP,并由此得到Minor function: PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp); ULONG Minorfunction = IrpStack->Minorfunction; //然后把这个Minor function传递给下一个设备栈: IoSkipCurrentIrpStackLocation(Irp); NTSTATUS status = IoCallDriver( dx->NextStackDevice, Irp); //处理“即插即用”次功能代码: //当Minor function等于IRP_MN_REMOVE_DEVICE时,说明有设备被拔出或卸下,这时要取消资源分配并删除设备: if( Minorfunction==IRP_MN_REMOVE_DEVICE) { //取消设备接口: IoSetDeviceInterfaceState(&dx->ifSymLinkName, FALSE); RtlFreeUnicodeString(&dx->ifSymLinkName); //调用IoDetachDevice()把fdo从设备栈中脱开: if (dx->NextStackDevice) IoDetachDevice(dx->NextStackDevice); //删除fdo: IoDeleteDevice(fdo); } //返回值: return status; } 下面为MakeFile文件 # # DO NOT EDIT THIS FILE!!! Edit .\\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV)\\makefile.def 下面为Source文件 TARGETNAME=HelloWDM TARGETTYPE=DRIVER DRIVERTYPE=WDM TARGETPATH=OBJ INCLUDES=$(BASEDIR)\\inc;\\ $(BASEDIR)\\inc\\ddk;\\ TARGETLIBS=$(BASEDIR)\\lib\\*\\free\\usbd.lib\\ SOURCES=HelloWDM.cpp\\ 我将这四个文件用DDK编译后就出现了如上的错误。驱动刚刚在入门的阶段,这些问题自己很难独立解决,望大家能够帮帮我。 简单只是对会者而言。 |
|
|
板凳#
发布于:2004-05-10 11:52
/***************************************************************
程序名称:Hello World for WDM 文件名称:HelloWDM.h ***************************************************************/ //头文件,只是声明一些函数和变量 #ifdef __cplusplus extern \"C\" { #endif #include <wdm.h> #ifdef __cplusplus } // extern \"C\" #endif #include \"ntddk.h\" typedef struct _DEVICE_EXTENSION { PDEVICE_OBJECT fdo; PDEVICE_OBJECT NextStackDevice; UNICODE_STRING ifSymLinkName; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; NTSTATUS HelloWDMAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject); NTSTATUS HelloWDMPnp(IN PDEVICE_OBJECT fdo, IN PIRP Irp); |
|
|
地板#
发布于:2004-05-10 13:44
谢谢,我看了三天,你一句话就解决了。真的是会者不难啊。
这里 #ifdef __cplusplus extern \"C\" { #endif #include <wdm.h> #ifdef __cplusplus } // extern \"C\" #endif #include \"ntddk.h\" 我查过__cplusplus它是一个预编译的宏,不过我对这个还是不太理解。 [编辑 - 5/10/04 by luhouxiang] |
|
|
地下室#
发布于:2004-05-10 14:01
你没细看内文 !!
//extern \"C\"是必须的,表示“用C链接”。如果你的文件名是HelloWDM.c的话,这句可以省略。 extern \"C\" <--- 这句出问题 !! |
|
5楼#
发布于:2004-05-12 17:22
改了头文件就可以编译通过了吗?麻烦告诉我一下,我也是新手,我怎么还是编译通不过啊?谢谢
|
|