#ifdef __COMMENT_ONLY // The following member functions are actually defined by the // a DEVMEMBER_XXX macro (such as DEVMEMBER_DISPATCHERS). // The macro __COMMENT_ONLY never gets defined. These comment-only // definitions simply allow easy navigation to the functions within // the Developer Studio using the class browser.
#define VDW_MAIN #include <khid.h> // Note: HID minidrivers include this rather than vdw.h #include "vhidmou.h" // the device class #include "vmoudev.h" // the driver class #pragma code_seg("INIT")
// Customize the policy for canceling the current IRP m_Policies.m_QueryRemovePolicy.m_CancelCurrentIrp = TRUE;
// Set up the VxD interface // m_Vxd.Initialize("VHIDMSE", VxdControlMessageHandler, this); }
// HIDCLASS calls this routine when it wants a report. We // serialize this IRP so that when we get input, we know // which IRP it is intended for. Note that HIDCLASS actually // created the device object, so we're assuming that HIDCLASS // is not using the device queue.
// Note: A driver that relies on a bus driver or some other // lower level device to process the IRP should generally not queue // the IRP. Queueing is primarily used by lowest level drivers. // If this rule is not followed, then the lower device's dispatch // routines will be called at raised IRQL, and this is generally // not good. }
// UpdateState // // Completes the current IRP if there is anything to report // VOID VirtualHidMouse::UpdateState(void) { KIrp I=CurrentIrp();
if ( !I.IsNull() ) { m_Lock.Lock();
if ( (m_DeltaX != 0) || (m_DeltaY != 0) || (m_NewButtonState != m_OldButtonState) ) { // Before processing the Irp, we need to check to see if it has been // canceled. We also want to set the Irp into an non-cancelable // state (cancel routine set to NULL) so we can process it. When // performing these operations, it is necessary to hold the global // cancel spin lock and take special precautions to ensure the Irp // is still valid. This is accomplished using the routine // KIrp::TestAndSetCancelRoutine(). if ( !I.TestAndSetCancelRoutine( LinkTo(CancelQueuedIrp), NULL, CurrentIrp()) ) {
// The Irp has been canceled we stop processing and exit. Since // it was in a cancelable state previously, it will be completed by // the cancel routine that had been set on it. return; }
////////////////////////////////////////////////////////////////// // VirtualHidMouse::DefaultPnp // // This handler is the override of KPnpDdevice::Default. It provides // default functionality for IRP_MJ_PNP. The // system invokes this function whenever the device receives a // Pnp IRP having a minor function for which the corresponding // member function of KPnpDevice is not overridden. Note that // KHidDevice provides overrides for some of the KPnpDevice members // (e.g. OnRemoveDevice). // // Subclasses should consider if this is the appropriate default // functionality. If not, override the function. // NTSTATUS VirtualHidMouse::DefaultPnp(KIrp I) { T << "DefaultPnp Pnp request, minor=" << ULONG(I.MinorFunction()) << "\n";
////////////////////////////////////////////////////////////////// // VirtualHidMouse::DefaultPower // // This handler is the override of KPnpDdevice::Default. It provides // default functionality for IRP_MJ_POWER. The // system invokes this function whenever the device receives a // Power IRP having a minor function for which the corresponding // member function of KPnpDevice is not overridden. // // Subclasses should consider if this is the appropriate default // functionality. If not, override the function. // NTSTATUS VirtualHidMouse::DefaultPower(KIrp I) { T << "DefaultPower Power request, minor=" << ULONG(I.MinorFunction()) << "\n";
//////////////////////////////////////////////////////////////////////////////// // SystemControl // // This routine just passes the IRP through to the next device since this driver // is not a WMI provider. // NTSTATUS VirtualHidMouse::SystemControl(KIrp I) { I.ForceReuseOfCurrentStackLocationInCalldown(); return m_Pdo.PnpCall(this, I); }
/////////////////////////////////////////////////////////////////// // OnQueryStopDevice // // This call queries the device to determine if a STOP can be done // NTSTATUS VirtualHidMouse::OnQueryStopDevice(KIrp I) { T << "OnQueryStopDevice()\n"; return STATUS_SUCCESS; }
/////////////////////////////////////////////////////////////////// // OnQueryRemoveDevice // // The system is querying the device to determine if a REMOVE can be done // NTSTATUS VirtualHidMouse::OnQueryRemoveDevice(KIrp I) { T << "OnQueryRemoveDevice()\n"; return STATUS_SUCCESS; }
/////////////////////////////////////////////////////////////////// // OnCancelStopDevice // // This call instructs the device to cancel a pending stop operation // NTSTATUS VirtualHidMouse::OnCancelStopDevice(KIrp I) { T << "OnCancelStopDevice()\n"; return STATUS_SUCCESS; }
/////////////////////////////////////////////////////////////////// // OnCancelRemoveDevice // // This call instructs the device to cancel a pending stop operation // NTSTATUS VirtualHidMouse::OnCancelRemoveDevice(KIrp I) { T << "OnCancelRemoveDevice()\n"; return STATUS_SUCCESS; }
/////////////////////////////////////////////////////////////////// // OnStartDevice // // This call instructs the device to start operation. Relevant // policies: // // m_Policies.m_CompletedByDriverWorks.m_StartDevice = TRUE // m_Policies.m_ForwardToPdoPolicy.m_CallBeforeStart = TRUE // NTSTATUS VirtualHidMouse::OnStartDevice(KIrp I) { T << "OnStartDevice()\n";
if (!m_State.m_Started) { // initialize the device }
return STATUS_SUCCESS; }
/////////////////////////////////////////////////////////////////// // OnStopDevice // // This call instructs the device to uninitialize itself. Relevant // policies: // // m_Policies.m_CompletedByDriverWorks.m_StopDevice = TRUE // m_Policies.m_ForwardToPdoPolicy.m_CallAfterStop = TRUE // m_Policies.m_HoldPolicy.m_CancelAllOnStop = TRUE // NTSTATUS VirtualHidMouse::OnStopDevice(KIrp I) { T << "OnStopDevice()\n";
if (m_State.m_Started) { // undo OnStartDevice here }
return STATUS_SUCCESS; // IRP completed by D::W }
////////////////////////////////////////////////////////////////// // VirtualHidMouse::OnRemoveDevice // // Override of KPnpDevice member. The system calls when the device // is removed. If a device has outstanding IRPs, it should make // sure they are all complete before deleting itself.
NTSTATUS VirtualHidMouse::OnRemoveDevice(KIrp I) { T << "OnRemoveDevice()\n"; return STATUS_SUCCESS; }