VC+DDK的环境设置

在Windows上,Windows   DDK提供的开发环境是基于命令行的,操作起来极为不便,相信进行过驱动程序开发的朋友一定对此深恶痛绝。另一方面,Visual   Studio   6.0却给我们提供了非常友好易用的集成环境,让我们有如虎添翼之感。     
    那么,能否利用Visual   Studio的集成环境来开发驱动程序呢?笔者经过多方探索,并结合自己开发驱动的经验,摸索出了一套实用的方法,通过对Visual   Studio集成环境的简单设置,创建了自己的驱动开发集成环境了。  下面笔者的一些经验奉献出来与大家共享,如有不当,欢迎指正。     
    
  0.系统要求已安装    
    DDK    
    Visual   C++6.0(安装时选上所有工具)    
   
  1.改造ddk/bin/setenv.bat    
    把要求mstools的有关语句注释掉(若想在命令行环境开发驱动则还需加入call   VC_DIR/VC98/Bin/Vcvars32. bat),以便能在命令行使用vc的相关工具;若只想在IDE环境开发就不必调用Vcvars32.bat,因为相关工具的路径信息可以在vc环境中设置.)    
   
  2.创建一个目录DriverEnv(目录名随意),作为你开发驱动的大本营    
   
  3.在该目录下创建一个批处理文件MakeDrvr.bat,内容如下:    
  @echo   off    
  if   "%1"==""   goto   usage    
  if   "%3"==""   goto   usage    
  if   not   exist   %1/bin/setenv.bat   goto   usage    
  call   %1/bin/setenv   %1   %4    
  %2    
   
  cd   %3    
  build   -b   -w   %5   %6   %7   %8   %9    
   
  goto   exit    
   
  :usage    
  echo   usage   MakeDrvr   DDK_dir   Driver_Drive   Driver_Dir   free/checked   [build_options]    
  echo   eg   MakeDrvr   %%DDKROOT%%   C:   %%WDMBOOK%%   free   -cef    
  :exit    
    该批处理首先对传递的参数作一些检查,然后调用ddk的setenv命令设置环境变量,然后改变目录为源程序所    
  在驱动器和目录,并最后调用build,-b保证显示完全的错误信息,-w保证在屏幕上输出警告,在vc   ide里的output窗口中可以看到这些错误和警告。    
   
  4.建立一个空白工程    
    选File的new菜单项,然后选project栏的makefile,然后输入路径,一路next下去即可,visual   studio提供两种配置win32   debug和win32   release.    
   
  5.修改这两种配置    
    选project的settings菜单项win32   debug:    
    在Build   Command   Line一栏填入MakeDrvr   DDK_DIR   SOURCE_DRIVE   SOURCE_DIR   checked   [build   options]    
    在Rebuild   all   options一栏填入   -nmake   /a    
    在output   file一栏填入与sources文件中的TARGETNAME相同的文件名    
    在Browse   info   file   name一栏填入obj/i386/checked/(与TARGETNAME相同的文件名,见下述).bsc    
   
    win32   release:    
    在Build   Command   Line一栏填入MakeDrvr   DDK_DIR   SOURCE_DRIVE   SOURCE_DIR   free   [build   options]    
    在Rebuild   all   options一栏填入   -nmake   /a    
    在output   file一栏填入与sources文件中的TARGETNAME相同的文件名    
    在Browse   info   file   name一栏填入obj/i386/free/(与TARGETNAME相同的文件名).bsc    
    注:DDK_DIR一般可以写成%BASEDIR%,build   options一般为-cef即已足够    
   
  6.添加源文件到工程    
    可以新建,也可以添加,这和普通的win32开发一样。    
   
  7.添加资源文件    
    选INSERT的RESOURCE菜单项即可    
   
  8.把文件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    
   
  9.把文件Sources放入源程序目录,内容为    
    TARGETNAME=RamDrive//这是要生成的驱动程序.sys文件的名字    
    TARGETPATH=obj   //.sys文件所在目录的上层目录,(由于ddk的bug)应手工在obj目录下创建checked和free目录,以作为.sys的最终存放目录    
    TARGETTYPE=DRIVER   //驱动程序的类型,一般不变    
    INCLUDES=$(BASEDIR)/inc   //ddk包含文件路径,一般不变    
    SOURCES=RamDrive.cpp   RamDrive.rc   //源文件(不要头文件),资源文件    
    BROWSER_INFO   =   1   //若想要浏览信息,则要有本行;否则可无    
   
  10.因为MakeDrvr.bat在DriverEnv目录,所以应把该目录添加到vc的Executable   files里面    
    选tools的options菜单项,然后选directories页,在show   directories   for一栏选择Executable   files,然后添加即可.    
   
    至此,环境设置完毕,你可以按F7,   build你的驱动程序了。
DDKWizard is a so-called project creation wizard that allows you to create projects that use the DDKBUILD scripts from OSR (also available in the download section from this site). The wizard will give you several options to configure your project prior to the creation. Have a look at figure 1. Figure 2: Project creation dialog (click to enlarge) Instead of forcing you to use a subset of options and specific DDKs this wizard lets you choose what you want. Of course the template files are predefined and so is the content of the project(s) within certain limits. However, I tried to choose the best options that I could think of and provide a way to create quickly and easily the DDKBUILD project you want. This means that I tried to leave out those things that may limit your choice lateron and add other options that will give you the flexibility to change options quickly long after the project was created. DDKWizard adds a new subfolder in the project creation wizard - see figure 2 - and presents all supported project types there. Currently these are Driver, Empty Driver, Native Application, Win32 console application and Win32 DLL. In either case you just choose the type of project to create, give the name of the project and/or solution as well as other options (at the bottom) and you are being presented the wizard dialog (see figure 1). From the wizard dialog you choose the DDKBUILD script you want to use, the DDK or multiple DDKs as well as the other options. If you are curious about the Property Sheet feature, please download the manual and read the respective section there. Compatibility DDKWizard (1.2.0a) has been tested on the following configurations: Visual Studio Professional .NET with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio Professional .NET 2003 with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual C++ 2005 Express with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio 2005 Professional with WNET DDK and DDKBUILD.CMD on Windows 2003 Server R2 Standard Visual Studio 2008 Professional with WNET DDK and DDKBUILD.CMD on Windows XP From this list one can deduce that it is supposed to also run if you got the respective "non-Express" Visual C++ version. Also if there has been some Visual C++ .NET 2003 Express DDKWizard is prepared for it. Download You could go watch the demo or download right away: Manual: contains the detailed description of how to configure DDKBUILD and use DDKWizard. If you are unsure whether you should download and install DDKWizard grab this file and skim over it. Download: ddkwiz_manual.pdf (~513kB, 2009-12-05@20-11-55, downloaded 31666 times) Installer (incl. manual) of DDKWizard 1.3.0a: this is the setup program which will install DDKWizard along with the manual on your computer and register it with Visual Studio. Download: ddkwizard_setup.exe (~557kB, 2009-12-05@20-12-37, downloaded 72787 times) DDKBUILD.CMD: Stable version 7.4/r60 of OSRs DDKBUILD NT script version. Feedback for this version can be sent to me directly. Download: ddkbuild_cmd.zip (~12kB, 2009-11-28@04-38-36, downloaded 20707 times) DDKBUILD.BAT (obsoleted by the above!): Version 6.12 of OSRs DDKBUILD batch script version. Download: ddkbuild_bat.zip (~6kB, 2008-03-21@15-59-07, downloaded 17226 times) Trunk version of DDKBUILD.CMD The version from trunk is available as well. Please note that this is not necessarily the same version as offered in the ZIP archive above. It may be in a better shape (e.g. reported bugs fixed) or slightly worse (e.g. new feature that is not yet stable). So use this version only if you want to test the latest development version and are able to provide feedback. Here is the link to the prettier ViewVC URL: ddkbuild/trunk - SVN clients get read-only access here. License All projects created by DDKWizard can be put under whatever license you like to put them. The scripts and HTML files which contain the DDKWizard logic are subject to the zlib license starting with version 1.2.0, before it was released under the GPL v2 from 1991. The zlib license is a lot more liberal and allows just about any kind of use for the script and "user interface" part of DDKWizard. The DDKBUILD scripts are mirrored with the permission of OSR. I will try to keep it synchronized at all times. Everything else Contact me here and also visit my blog and my website. Note that I usually announce new versions of DDKWizard and DDKBUILD on my blog - you also might want to subscribe to the RSS feed for DDKWizard and DDKBUILD. This page will be extended whenever I deem it necessary.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值