当前位置: 代码迷 >> 驱动开发 >> 张帆驱动开发书里第四章实验 KdPrint 糊涂,该如何处理
  详细解决方案

张帆驱动开发书里第四章实验 KdPrint 糊涂,该如何处理

热度:276   发布时间:2016-04-28 10:58:19.0
张帆驱动开发书里第四章实验 KdPrint 糊涂
C/C++ code
void Dump(IN PDRIVER_OBJECT pDriverObject){             KdPrint(("----------------------------------------------\n"));    KdPrint(("开始输出信息...\n"));    KdPrint(("Driver Address:0X%08X\n",pDriverObject));    KdPrint(("Driver name:%wZ\n",&pDriverObject->DriverName));    KdPrint(("Driver HardwareDatabase:%wZ\n",pDriverObject->HardwareDatabase));    KdPrint(("Driver first device:0X%08X\n",pDriverObject->DeviceObject));         int i=1;    PDEVICE_OBJECT pDevice;    pDevice = pDriverObject->DeviceObject;    for (;pDevice!=NULL;pDevice = pDevice->NextDevice)    {        KdPrint(("The %d device\n",i++));        KdPrint(("Device AttachedDevice:0X%08X\n",pDevice->AttachedDevice));        KdPrint(("Device NextDevice:0X%08X\n",pDevice->NextDevice));        KdPrint(("Device StackSize:%d\n",pDevice->StackSize));        KdPrint(("Device's DriverObject:0X%08X\n",pDevice->DriverObject));    }        KdPrint(("输出结束!\n"));    KdPrint(("----------------------------------------------\n"));}


error C2275: 'PDEVICE_OBJECT' : illegal use of this type as an expression 会出现一堆错误
如果我把
int i=1;
PDEVICE_OBJECT pDevice;
pDevice = pDriverObject->DeviceObject;
这三句放到最前面就没事 KdPrint这个宏 有什么特殊的吗? 糊涂 忘高手指点
C/C++ code
void Dump(IN PDRIVER_OBJECT pDriverObject){    int i=1;    PDEVICE_OBJECT pDevice;    pDevice = pDriverObject->DeviceObject;        KdPrint(("----------------------------------------------\n"));    KdPrint(("开始输出信息...\n"));    KdPrint(("Driver Address:0X%08X\n",pDriverObject));    KdPrint(("Driver name:%wZ\n",&pDriverObject->DriverName));    KdPrint(("Driver HardwareDatabase:%wZ\n",pDriverObject->HardwareDatabase));    KdPrint(("Driver first device:0X%08X\n",pDriverObject->DeviceObject));        for (;pDevice!=NULL;pDevice = pDevice->NextDevice)    {        KdPrint(("The %d device\n",i++));        KdPrint(("Device AttachedDevice:0X%08X\n",pDevice->AttachedDevice));        KdPrint(("Device NextDevice:0X%08X\n",pDevice->NextDevice));        KdPrint(("Device StackSize:%d\n",pDevice->StackSize));        KdPrint(("Device's DriverObject:0X%08X\n",pDevice->DriverObject));    }        KdPrint(("输出结束!\n"));    KdPrint(("----------------------------------------------\n"));}


------解决方案--------------------
你别说你是用.c而不是.cpp?????
------解决方案--------------------
用C语言写的,扩展名为.c

对于c代码,必须将变量声明放在函数头部,前面不能有语句。

PDEVICE_OBJECT 的定义


KdPrint使用方法