Thanks Peter…Here is my code for the device add…
NTSTATUS
DioEvtDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
WDF_OBJECT_ATTRIBUTES objAttributes;
WDFDEVICE device;
PDIO_DEVICE_CONTEXT devContext;
WDF_IO_QUEUE_CONFIG ioCallbacks;
//WDF_INTERRUPT_CONFIG interruptConfig;
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings;
WDF_FILEOBJECT_CONFIG fileObjectConfig;
DECLARE_CONST_UNICODE_STRING(ntDeviceName, L"\Device\WDFDIO");
DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\WDFDIO");
//
// Initialize the PnpPowerCallbacks structure.
//
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
//
// Setup the callbacks to manage our hardware resources.
//
// Prepare is called at START_DEVICE time
// Release is called at STOP_DEVICE or REMOVE_DEVICE time
//
pnpPowerCallbacks.EvtDevicePrepareHardware = DioEvtPrepareHardware;
pnpPowerCallbacks.EvtDeviceReleaseHardware = DioEvtReleaseHardware;
//
// These two callbacks set up and tear down hardware state that must be
// done every time the device moves in and out of the D0-working state.
//
pnpPowerCallbacks.EvtDeviceD0Entry= DioEvtDeviceD0Entry;
pnpPowerCallbacks.EvtDeviceD0Exit = DioEvtDeviceD0Exit;
//
// Register the PnP and power callbacks. Power policy related callbacks will
// be registered later in SotwareInit.
//
WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
//
// Create our Device Object and its associated context
//
WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);
//
// Associate our device context structure type with our WDFDevice
//
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&objAttributes, DIO_DEVICE_CONTEXT);
//
// Other attributes we might set are EvtCleanupCallback (called when
// the object is deleted) and EvtDestroyCallback (called when the object’s
// references go to zero)…
//
//
// Set the synch scope to device so that child objects such as queue
// and DpcForIsr can inherit the device-level synchronization. By
// doing so, we make sure that queue dispatch callbacks for ioctl,
// cancel-routine, and DpcForIsr are all synchronized with the
// same device-level spinlock provided by the framework. This enables
// us to access global resources among these callbacks without
// worrying about synchronizing access to them with our own lock.
//
objAttributes.SynchronizationScope = WdfSynchronizationScopeDevice;
//
// We want our device object NAMED, thank you very much
//
status = WdfDeviceInitAssignName(DeviceInit, &ntDeviceName);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfDeviceInitAssignName failed 0x%0x\n”, status);
return(status);
}
//
// Create the device now
//
status = WdfDeviceCreate(&DeviceInit, // Device Init structure
&objAttributes, // Attributes for WDF Device
&device); // returns pointer to new WDF Device
if ( !NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfDeviceInitialize failed 0x%0x\n”, status);
return(status);
}
//
// Device creation is complete
//
//
// Create a symbolic link for the control object so that usermode can open
// the device.
//
status = WdfDeviceCreateSymbolicLink(device, &dosDeviceName);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfDeviceCreateSymbolicLink failed 0x%0x\n”, status);
return(status);
}
//
// Configure our queue of incoming requests
//
// We only use the default queue, and we only support IRP_MJ_DEVICE_CONTROL.
// Not supplying a callback results in the request being completed
// with STATUS_NOT_SUPPORTED. So, note that this driver does not support
// either IRP_MJ_READ or IRP_MJ_WRITE.
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioCallbacks,
WdfIoQueueDispatchSequential);
ioCallbacks.EvtIoDeviceControl = DioEvtDeviceControl;
status = WdfIoQueueCreate(device,
&ioCallbacks,
WDF_NO_OBJECT_ATTRIBUTES,
NULL); // optional pointer to receive queue handle
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfIoQueueCreate for default queue failed 0x%0x\n”, status);
return(status);
}
//
// Get our device context
//
devContext = DioGetContextFromDevice(device);
//
// Store a pointer to our WDF Device
//
devContext->WdfDevice = device;
//
// Create an interrupt object that will later be associated with the
// device’s interrupt resource and connected by the Framework.
//
/*WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&objAttributes, INTERRUPT_DATA);
//
// Configure the Interrupt object
//
WDF_INTERRUPT_CONFIG_INIT(&interruptConfig,
DioIsr,
DioDpc);
interruptConfig.AutomaticSerialization = TRUE;
interruptConfig.EvtInterruptEnable = DioEvtInterruptEnable;
interruptConfig.EvtInterruptDisable = DioEvtInterruptDisable;
status = WdfInterruptCreate(device,
&interruptConfig,
&objAttributes,
&devContext->WdfInterrupt);
if (!NT_SUCCESS (status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfInterruptCreate failed 0x%0x\n”, status);
return status;
}*/
//
// Initialize our idle policy
// We accept ALL the defaults here, meaning that our device will idle in
// D3 when it’s not busy… after 5 seconds. Also, we allow WDF to create
// a Device Manager property sheet that’ll allow an appropriately priv’d
// user to determine whether or not the device should power-off idle.
//
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings,
IdleCannotWakeFromS0);
status = WdfDeviceAssignS0IdleSettings(device, &idleSettings);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, AMCC_TRACE_INIT,“WdfDeviceUpdateS0IdleSettings failed 0x%0x\n”, status);
return status;
}
return(status);
}
Here is the application code for opening the device
{
HANDLE DriverHandle;
DWORD code;
ULONG index;
ULONG function;
// Open the device
//
DriverHandle = CreateFile(“\\.\WDFDIO”, // Name of the “device” to open
GENERIC_READ|GENERIC_WRITE, // Access rights requested
0, // Share access - NONE
0, // Security attributes - not used!
OPEN_EXISTING, // Device must exist to open it.
FILE_FLAG_OVERLAPPED, // Open for overlapped I/O
0); // extended attributes - not used!
//
// If this call fails, check to figure out what the error is and report it.
//
if (DriverHandle == INVALID_HANDLE_VALUE) {
code = GetLastError();
printf(“CreateFile failed with error 0x%x\n”, code);
return(code);
}
}
In the CreateFile function, I tried giving "\\.\Device\WDFDIO " and “\Device\WDFDIO” also but that too didnt work…
Thanks for the help.