通过WDK编译驱动出现的错误

刚开始跟随着老大学习驱动开发,真的很开心机缘巧合的拥有了这次机会。。。

刚接触驱动方面的开发,老大把公司里的驱动源代码发给我们看,大概浏览了一下就像看“有字天书”一样,有太多太多看不懂的地方。

最终决定还是从基础知识学起,我选择 ”寒江独钓-Windows内核安全编程(清晰完整版).pdf ",首先很感谢书的相关作者,谭文、杨潇等等。,里面从浅入深,从各编译、调试环境配置到驱动开发所应用领域(含源代码)。。

 

转入正题:

刚接触,从开发到编译驱动遇到了不少麻烦,以下是这两天遇到的问题,可能对于驱动高手来说,这些问题真是太低级了,

但是花了我不少时间解决,网上搜了,结果不理想。现在记录起来,也为日后解决问题提供查找资源吧。。

 

 

通过WDK编译驱动时没常会出现以下错误.


1>Compiling and Linking e:/my drivers/comcap *************
1>'nmake.exe /nologo BUILDMSG=Stop. -i BUILD_PASS=PASS2 LINKONLY=1 NOPASS0=1 MAKEDIR_RELATIVE_TO_BASEDIR='
1>e:/my drivers/comcap: TARGETPATH is obj
1>e:/winddk/7600.16385.1/bin/makefile.new(7117) : fatal error U1087: cannot have : and :: dependents for same target
1>errors in directory e:/my drivers/comcap
1>e:/winddk/7600.16385.1/bin/makefile.new(7117) : error U1087: cannot have : and :: dependents for same target
1>Stop.
1>nmake.exe /nologo BUILDMSG=Stop. -i BUILD_PASS=PASS2 LINKONLY=1 NOPASS0=1 MAKEDIR_RELATIVE_TO_BASEDIR= failed - rc = 2

 

--------------------------------------------------------------------------------------------------------

引起此错误原因是由于 编译驱动路径出现了空格如上图:e:/my drivers/comcap
解决方案:把路径中的空格去掉就可以了e:/mydrivers/comcap

随便说一下,在winDbg中打开源文件调试时,由于路径有空格同样会出现问题。。

-----------------------------------------------------------------------------------------------------

 

 

 


1>e:/mydrivers/comcap/comcap.c(89) : warning C4133: '=' : incompatible types - from 'PDEVICE_OBJECT' to 'PDRIVER_OBJECT'
1>warnings in directory e:/mydrivers/comcap
1>e:/mydrivers/comcap/comcap.c(89) : warning C4133: '=' : incompatible types - from 'PDEVICE_OBJECT' to 'PDRIVER_OBJECT'
1>e:/mydrivers/comcap/comcap.c(100) : warning C4133: '=' : incompatible types - from 'PDRIVER_OBJECT' to 'PDEVICE_OBJECT'
1>e:/mydrivers/comcap/comcap.c(100) : warning C4133: '=' : incompatible types - from 'PDRIVER_OBJECT' to 'PDEVICE_OBJECT'
1>e:/mydrivers/comcap/comcap.c(237) : error C2275: 'ULONG' : illegal use of this type as an expression
1>errors in directory e:/mydrivers/comcap
1>e:/mydrivers/comcap/comcap.c(237) : error C2275: 'ULONG' : illegal use of this type as an expression
1> e:/winddk/7600.16385.1/inc/api/ntdef.h(561) : see declaration of 'ULONG'
1>e:/mydrivers/comcap/comcap.c(237) : error C2146: syntax error : missing ';' before identifier 'i'
1>e:/mydrivers/comcap/comcap.c(237) : error C2146: syntax error : missing ';' before identifier 'i'
1>e:/mydrivers/comcap/comcap.c(237) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(237) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(239) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(242) : error C2065: 'i' : undeclared identifier
1>e:/mydrivers/comcap/comcap.c(242) : error C2065: 'i' : undeclared identifier

 

 

问题代码定义:
#if DBG

_asm int 3
#endif
 ULONG i;

 

 

------------------------------------------------------------------------------------------------------------

不知道是不是由于WDK编译环境的问题,如果在变量定义前执行其他操作,则会出现上图所示错误。
如上代码.
解决方案:尽量把方法体中所需要的变量提前定义好,然后再进行其他操作

---------------------------------------------------------------------------------------------------------
NTSTATUS DriverEntry (PDRIVER_OBJECT driver , PUNICODE_STRING RegistryPath)
 {
 
 ULONG i;

UNICODE_STRING printText=RTL_CONSTANT_STRING(L"阿标的驱动测试输出信息/r/n");
DbgPrint("%wZ",&printText);//printText为指针
 #if DBG
_asm int 3
#endif

for(i = 0; i< IRP_MJ_MAXIMUM_FUNCTION;i ++)
{

driver->MajorFunction[i] =ccpDispatch;
 
}

 

//支持动态卸载
 driver->DriverUnload=ccpUnload;
//绑定所有接口
ccpAttachAllComs(driver);

return STATUS_SUCCESS;
  
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值