Hello,
We have a kmdf, software only, non-Pnp driver. In the driver's main source file,
we do the following to set up a context area that holds the WDFDEVICE
for the driver.
**************** CONTEXTAREA.H ***************
typedef struct _REQUEST_CONTEXT
{
WDFDEVICE wdfDevice;
} REQUEST_CONTEXT, *PREQUEST_CONTEXT;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(REQUEST_CONTEXT, GetRequestContext)
***************************************
*********** DRIVER.C *********************
(error checking removed for brevity)
#include "contextarea.h"
.
.
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, REQUEST_CONTEXT);
status = WdfDeviceCreate(&DeviceInit,
&attributes,
&controlDevice);
// Save the WDFDEVICE in our context area so
// source code in external functions outside of
// this file can access it.
context = GetRequestContext(controlDevice);
context->wdfDevice = controlDevice;
*******************************************
************** DOIOCTL.C **********************
// In this file we have an IOCTL function that is called
// by the main driver code to do a task.
#include "contextarea.h"
.
.
NTSTATUS DoMyIOCTL(
IN WDFREQUEST theRequest,
IN size_t theInputBufferLength,
IN size_t theOutputBufferLength,
IN OUT size_t *bytesCopied)
// We need to send an IOCTL request to another
// device. We need to retrieve the WDFDEVICE
// for our driver from the context area so
/// WdfIoTargetCreate() will know the source of
// the IOCTL request.
//
// So, I assumed that I would call the context
// area accessor, but it failed and required
// the WDFDEVICE as a parameter, which we we
// saved in the context area! A bit of the
// chicken before the egg...
// So, I am hoping that someone can tell me how I can make the following
// code work. Once I have the ioTarget, the rest should flow pretty easily.
Thank you for your comments and help!
Mike
context = GetRequestContext();
status = WdfIoTargetCreate(WdfIoTargetGetDevice(context->wdfDevice),
WDF_NO_OBJECT_ATTRIBUTES, &ioTarget);