CPCIIODriver.cpp
上传用户:lu7552215
上传日期:2021-11-14
资源大小:15k
文件大小:5k
源码类别:

驱动编程

开发平台:

Visual C++

  1. // CPCIIODriver.cpp
  2. //
  3. // Generated by DriverWizard 3.2.0 (Build 2485)
  4. // Requires DDK and DriverWorks
  5. // File created on 10/22/2008
  6. //
  7. // This source file contains the implementation of a subclass of KDriver.
  8. // WDM drivers implement a subclass of KDriver and override member
  9. // function DriverEntry and AddDevice.
  10. //
  11. #define VDW_MAIN
  12. #include <vdw.h>
  13. #include "function.h"
  14. #include "CPCIIODriver.h"
  15. #include "CPCIIODevice.h"
  16. #pragma hdrstop("CPCIIO.pch")
  17. // Memory allocation pool tag
  18. // Override this value using the global function SetPoolTag().
  19. POOLTAG DefaultPoolTag('ICPC');
  20. // Global driver trace object
  21. // TODO: Use KDebugOnlyTrace if you want trace messages
  22. // to appear only in checked builds.  Use KTrace if
  23. // you want trace messages to always appear.  Call
  24. // method SetOutputLevel to set the output threshold.
  25. KDebugOnlyTrace T("CPCIIO");
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // Begin INIT section
  28. #pragma code_seg("INIT")
  29. DECLARE_DRIVER_CLASS(CPCIIODriver, NULL)
  30. ///////////////////////////////////////////////////////////////////////////////////////////////////
  31. //  CPCIIODriver::DriverEntry
  32. // This routine is called when the driver is loaded.  Drivers often 
  33. // read the registry for configurable parameters.
  34. //
  35. // Arguments:
  36. // IN RegistryPath
  37. // pointer to a unicode string representing the path to
  38. // driver-specific key in the registry.  Look for:
  39. // HKLMSYSTEMCurrentControlSetServicesCPCIIO
  40. //
  41. // Return Value:
  42. // NTSTATUS code
  43. //
  44. NTSTATUS CPCIIODriver::DriverEntry(PUNICODE_STRING RegistryPath)
  45. {
  46. T.Trace(TraceInfo, __FUNCTION__"++. Compiled at " __TIME__ " on " __DATE__ "n");
  47. #ifdef DBG
  48. //DbgBreakPoint();
  49. #endif
  50. NTSTATUS status = STATUS_SUCCESS;
  51. m_Unit = 0;
  52. // This macro suppresses compiler warning for unreferenced variable.
  53. // If you reference this parameter, simply remove the macro.
  54. UNREFERENCED_PARAMETER(RegistryPath);
  55. T.Trace(TraceInfo, __FUNCTION__"--. STATUS %xn", status);
  56. return status;
  57. }
  58. ///////////////////////////////////////////////////////////////////////////////////////////////////
  59. #pragma code_seg() // end INIT code
  60. ///////////////////////////////////////////////////////////////////////////////////////////////////
  61. ///////////////////////////////////////////////////////////////////////////////////////////////////
  62. //  CPCIIODriver::AddDevice
  63. // This routine is called when the system detects a device for which this
  64. // driver is responsible.  This function creates the Functional Device 
  65. // Object, or FDO. The FDO enables this driver to handle requests for  
  66. // the physical device.
  67. //
  68. // Arguments:
  69. // IN Pdo
  70. // Physical Device Object.  This is a pointer to a system device
  71. // object that represents the physical device.
  72. //
  73. // Return Value:
  74. // NTSTATUS
  75. //
  76. NTSTATUS CPCIIODriver::AddDevice(PDEVICE_OBJECT Pdo)
  77. {
  78. T.Trace(TraceInfo, __FUNCTION__"++.n");
  79. NTSTATUS status = STATUS_SUCCESS;
  80. // Create CPCIIODevice using a form of "placement" new
  81. // that is a member operator of KDevice.  This will use storage
  82. // in the system device object extension to store the class instance.
  83. CPCIIODevice* pDevice = new (
  84. static_cast<PCWSTR>(KUnitizedName(L"CPCIIODevice", m_Unit)),
  85. FILE_DEVICE_UNKNOWN,
  86. static_cast<PCWSTR>(KUnitizedName(L"CPCIIODevice", m_Unit)), 
  87. 0,
  88. DO_DIRECT_IO
  89. | DO_EXCLUSIVE
  90. | DO_POWER_PAGABLE
  91. )
  92. CPCIIODevice(Pdo, m_Unit);
  93. if (pDevice == NULL)
  94. {
  95. status = STATUS_INSUFFICIENT_RESOURCES;
  96. }
  97. else
  98. {
  99. status = pDevice->ConstructorStatus();
  100. if (!NT_SUCCESS(status))
  101. {
  102. delete pDevice;
  103. }
  104. else
  105. {
  106. m_Unit++;
  107. pDevice->ReportNewDevicePowerState(PowerDeviceD0);
  108. }
  109. }
  110. T.Trace(TraceInfo, __FUNCTION__"--. STATUS %xn", status);
  111. return status;
  112. }
  113. ///////////////////////////////////////////////////////////////////////////////////////////////////
  114. //  CPCIIODriver::Unload
  115. // This routine is called when the driver is unloaded.  Delete any
  116. // device objects created in DriverEntry by calling base class method
  117. // Unload().  Cleanup any allocations made for registry values in
  118. // DriverEntry.  
  119. //
  120. // Arguments:
  121. // none
  122. //
  123. // Return Value:
  124. // none
  125. //
  126. VOID CPCIIODriver::Unload(VOID)
  127. {
  128. T.Trace(TraceInfo, __FUNCTION__"++.n");
  129. // If you don't need to perform any functions
  130. // except to call the base class KDriver::Unload(),
  131. // then this entire routine may be safely deleted.
  132.     // Call base class to delete all devices.
  133. KDriver::Unload();
  134. T.Trace(TraceInfo, __FUNCTION__"--.n");
  135. }