zhaofree2001
驱动牛犊
驱动牛犊
  • 注册日期2005-06-12
  • 最后登录2013-02-08
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望40点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1983回复:2

为什么用DriverWizard生成的DriverEntry只有一个参数

楼主#
更多 发布于:2012-11-30 14:28
看了很多wdm的资料, 上面说的DriverEntry都有两个参数
DriverEntry ( IN PDRIVER_OBJECT DriverObject,    IN PUNICODE_STRING RegistryPath )
 
而用DriverWizard生成的只有一个参数, 这如何对应起来
NTSTATUS usbdrvtestDriver::DriverEntry(PUNICODE_STRING RegistryPath)
 
 
========================生成的相关程序如下(usbdrvtestDriver.cpp)=========================
 

// usbdrvtestDriver.cpp
//
// Generated by DriverWizard 3.2.0 (Build 2485)
// Requires DDK and DriverWorks
// File created on 11/26/2012
//
// This source file contains the implementation of a subclass of KDriver.
// WDM drivers implement a subclass of KDriver and override member
// function DriverEntry and AddDevice.
//
#define VDW_MAIN
#include <vdw.h>
#include <kusb.h>
#include <kusbbusintf.h>
#include "function.h"
#include "usbdrvtestDriver.h"
#include "usbdrvtestDevice.h"
#pragma hdrstop("usbdrvtest.pch")
// Memory allocation pool tag
// Override this value using the global function SetPoolTag().
POOLTAG DefaultPoolTag('dbsu');
// Global driver trace object
// TODO: Use KDebugOnlyTrace if you want trace messages
//   to appear only in checked builds.  Use KTrace if
//   you want trace messages to always appear.  Call
//   method SetOutputLevel to set the output threshold.
KDebugOnlyTrace T("usbdrvtest");
///////////////////////////////////////////////////////////////////////////////////////////////////
// Begin INIT section
#pragma code_seg("INIT")
DECLARE_DRIVER_CLASS(usbdrvtestDriver, NULL)
///////////////////////////////////////////////////////////////////////////////////////////////////
//  usbdrvtestDriver::DriverEntry
//  This routine is called when the driver is loaded.  Drivers often
//  read the registry for configurable parameters.
//
// Arguments:
//  IN RegistryPath
//    pointer to a unicode string representing the path to
//    driver-specific key in the registry.  Look for:
//    HKLM\SYSTEM\CurrentControlSet\Services\usbdrvtest
//
// Return Value:
//  NTSTATUS code
//
NTSTATUS usbdrvtestDriver::DriverEntry(PUNICODE_STRING RegistryPath)
{
 T.Trace(TraceInfo, __FUNCTION__"++. Compiled at " __TIME__ " on " __DATE__ "\n");
#ifdef DBG
 //DbgBreakPoint();
#endif
 NTSTATUS status = STATUS_SUCCESS;
 m_Unit = 0;
 // This macro suppresses compiler warning for unreferenced variable.
 // If you reference this parameter, simply remove the macro.
 UNREFERENCED_PARAMETER(RegistryPath);
 T.Trace(TraceInfo, __FUNCTION__"--. STATUS %x\n", status);
 return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma code_seg() // end INIT code
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//  usbdrvtestDriver::AddDevice
//  This routine is called when the system detects a device for which this
//  driver is responsible.  This function creates the Functional Device
//  Object, or FDO. The FDO enables this driver to handle requests for  
//  the physical device.
//
// Arguments:
//  IN Pdo
//    Physical Device Object.  This is a pointer to a system device
//    object that represents the physical device.
//
// Return Value:
//  NTSTATUS
//
NTSTATUS usbdrvtestDriver::AddDevice(PDEVICE_OBJECT Pdo)
{
 T.Trace(TraceInfo, __FUNCTION__"++.\n");
 NTSTATUS status = STATUS_SUCCESS;
 // Create usbdrvtestDevice using a form of "placement" new
 // that is a member operator of KDevice.  This will use storage
 // in the system device object extension to store the class instance.
 usbdrvtestDevice* pDevice = new (
            NULL,                    // no name
   FILE_DEVICE_UNKNOWN,
            NULL,                    // no name
   0,
   DO_BUFFERED_IO
    | DO_POWER_PAGABLE
   )
  usbdrvtestDevice(Pdo, m_Unit);
 if (pDevice == NULL)
 {
  status = STATUS_INSUFFICIENT_RESOURCES;
 }
 else
 {
  status = pDevice->ConstructorStatus();
  if (!NT_SUCCESS(status))
  {
   delete pDevice;
  }
  else
  {
   m_Unit++;
   pDevice->ReportNewDevicePowerState(PowerDeviceD0);
  }
 }
 T.Trace(TraceInfo, __FUNCTION__"--. STATUS %x\n", status);
 return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//  usbdrvtestDriver::Unload
//  This routine is called when the driver is unloaded.  Delete any
//  device objects created in DriverEntry by calling base class method
//  Unload().  Cleanup any allocations made for registry values in
//  DriverEntry.  
//
// Arguments:
//  none
//
// Return Value:
//  none
//
VOID usbdrvtestDriver::Unload(VOID)
{
 T.Trace(TraceInfo, __FUNCTION__"++.\n");
 // If you don't need to perform any functions
 // except to call the base class KDriver::Unload(),
 // then this entire routine may be safely deleted.
    // Call base class to delete all devices.
 KDriver::Unload();
 T.Trace(TraceInfo, __FUNCTION__"--.\n");
}
zhaofree2001
驱动牛犊
驱动牛犊
  • 注册日期2005-06-12
  • 最后登录2013-02-08
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望40点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2012-11-30 15:19
找到一些热心网友的参考, 先贴在这里

用DriverWorks生成的并不是标准的入口函数,而是在KDriver中的类函数,你可以看看

DriverWorks的帮助。

你的这段代码是书中的演示程序,如果非得强制放到DriverWorks生成的代码中不仅要看这本书

,还要看DriverWorks帮助,查找Kdriver,KlowerDriver等函数,另外,使用DriverWorks的好

处是很多都被封装到了CLASS中,你无需关心,比如其中的AddDevice,在DriverWorks中已经定

义了这个函数,生成的代码只是继承过来的,所以我觉得如果你只是想调试这段程序,还是不

用DriverWorks生成的好,你可以自己写入代码,我也遇到了这样的问题,原来的程序就是

DriverWorks生成的,现在需要某些参数时不得不重载再DriverWorks的函数来获得。

希望我已经讲明白了
paulai
驱动牛犊
驱动牛犊
  • 注册日期2013-02-18
  • 最后登录2013-02-18
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望51点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2013-02-18 18:21
有邦助
游客

返回顶部