Collapse the table of content
Expand the table of content
Expand Minimize

WdfUsbTargetPipeWriteSynchronously method

[Applies to KMDF and UMDF]

The WdfUsbTargetPipeWriteSynchronously method builds a write request and sends it synchronously to a specified USB output pipe.


NTSTATUS WdfUsbTargetPipeWriteSynchronously(
  [in]            WDFUSBPIPE                Pipe,
  [in, optional]  WDFREQUEST                Request,
  [in, optional]  PWDF_REQUEST_SEND_OPTIONS RequestOptions,
  [in, optional]  PWDF_MEMORY_DESCRIPTOR    MemoryDescriptor,
  [out, optional] PULONG                    BytesWritten


Pipe [in]

A handle to a framework pipe object that was obtained by calling WdfUsbInterfaceGetConfiguredPipe.

Request [in, optional]

A handle to a framework request object. This parameter is optional and can be NULL. For more information, see the following Remarks section.

RequestOptions [in, optional]

A pointer to a caller-allocated WDF_REQUEST_SEND_OPTIONS structure that specifies options for the request. This pointer is optional and can be NULL. For more information, see the following Remarks section.

MemoryDescriptor [in, optional]

A pointer to a caller-allocated WDF_MEMORY_DESCRIPTOR structure that describes the buffer that contains data that will be written to the device. For more information about this buffer, see the following Remarks section.

BytesWritten [out, optional]

A pointer to a location that receives the number of bytes written, if the operation succeeds. This parameter is optional and can be NULL.

Return value

WdfUsbTargetPipeWriteSynchronously returns the I/O target's completion status value if the operation succeeds. Otherwise, this method might return one of the following values:

Return codeDescription

The size of the WDF_REQUEST_SEND_OPTIONS structure that the RequestOptions parameter points to was incorrect.


An invalid parameter was detected.


Insufficient memory was available.


The caller's IRQL was not PASSIVE_LEVEL, an invalid memory descriptor was specified, the pipe's type was not valid, the transfer direction was invalid, or the specified I/O request was already queued to an I/O target.


The driver supplied a time-out value and the request did not complete within the allotted time.


The I/O request packet (IRP) that the Request parameter represents does not provide enough IO_STACK_LOCATION structures to allow the driver to forward the request.


This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.


Use the WdfUsbTargetPipeWriteSynchronously method to send write requests synchronously. To send write requests asynchronously, use WdfUsbTargetPipeFormatRequestForWrite, followed by WdfRequestSend.

The specified pipe must be an output pipe, and the pipe's type must be WdfUsbPipeTypeBulk or WdfUsbPipeTypeInterrupt.

The WdfUsbTargetPipeWriteSynchronously method does not return until the request has completed, unless the driver supplies a time-out value in the RequestOptions parameter's WDF_REQUEST_SEND_OPTIONS structure, or unless an error is detected.

You can forward an I/O request that your driver received in an I/O queue, or you can create and send a new request. In either case, the framework requires a request object and some buffer space.

To forward an I/O request that your driver received in an I/O queue:

  1. Specify the received request's handle for the Request parameter.

  2. Use the received request's input buffer for the MemoryDescriptor parameter.

    The driver must call WdfRequestRetrieveInputMemory to obtain a handle to a framework memory object that represents the request's input buffer and then place that handle in the WDF_MEMORY_DESCRIPTOR structure that MemoryDescriptor points to.

For more information about forwarding an I/O request, see Forwarding I/O Requests.

Drivers often divide received I/O requests into smaller requests that they send to an I/O target, so your driver might create new requests.

To create a new I/O request:

  1. Supply a NULL request handle for the WdfUsbTargetPipeWriteSynchronously method's Request parameter, or create a new request object and supply its handle:

    • If you supply a NULL request handle, the framework uses an internal request object. This technique is simple to use, but the driver cannot cancel the request.
    • If you call WdfRequestCreate to create one or more request objects, you can reuse these request objects by calling WdfRequestReuse. This technique enables your driver's EvtDriverDeviceAdd callback function to preallocate request objects for a device. Additionally, another driver thread can call WdfRequestCancelSentRequest to cancel the request, if necessary.

    Your driver can specify a non-NULL RequestOptions parameter, whether the driver provides a non-NULL or a NULL Request parameter. You can, for example, use the RequestOptions parameter to specify a time-out value.

  2. Provide buffer space for the WdfUsbTargetPipeWriteSynchronously method's MemoryDescriptor parameter.

    Your driver can specify this buffer space as a locally allocated buffer, as a WDFMEMORY handle, or as a MDL. You can use whichever method is most convenient.

    If necessary, the framework converts the buffer description to one that is correct for the I/O target's method for accessing data buffers.

    The following techniques are available:

    • Supply a local buffer

      Because WdfUsbTargetPipeWriteSynchronously handles I/O requests synchronously, the driver can create request buffers that are local to the calling routine, as the following code example shows.

      WDF_MEMORY_DESCRIPTOR  memoryDescriptor;
      MY_BUFFER_TYPE  myBuffer;
                                        (PVOID) &myBuffer,
    • Supply a WDFMEMORY handle

      Call WdfMemoryCreate or WdfMemoryCreatePreallocated to obtain a handle to framework-managed memory, as the following code example shows.

      WDF_MEMORY_DESCRIPTOR  memoryDescriptor;
      WDFMEMORY  memoryHandle = NULL;
      status = WdfMemoryCreate(NULL,

      Alternatively, the driver can call WdfRequestRetrieveInputMemory to obtain a handle to a framework memory object that represents a received I/O request's input buffer, if you want the driver to pass that buffer's contents to the I/O target. The driver must not complete the received I/O request until the new request that WdfUsbTargetPipeWriteSynchronously sends to the I/O target has been deleted, reused, or reformatted. (WdfUsbTargetPipeWriteSynchronously increments the memory object's reference count. Deleting, reusing, or reformatting a request object decrements the memory object's reference count.)

    • Supply a MDL

      Drivers can obtain the MDL that is associated with a received I/O request by calling WdfRequestRetrieveInputWdmMdl.

For information about obtaining status information after an I/O request completes, see Obtaining Completion Information.

For more information about the WdfUsbTargetPipeWriteSynchronously method and USB I/O targets, see USB I/O Targets.


The following code example creates a memory object, obtains a pointer to the object's buffer, fills the buffer, and uses the buffer as input to WdfUsbTargetPipeWriteSynchronously.

WDFMEMORY  wdfMemory;
ULONG  writeSize, bytesWritten;
size_t  bufferSize;
NTSTATUS status;

writeSize = SMALL_BUF_LEN;
status = WdfMemoryCreate(
if (!NT_SUCCESS(status)){
    return status;

writeBuffer = WdfMemoryGetBuffer(



status = WdfUsbTargetPipeWriteSynchronously(


Target platform


Minimum KMDF version


Minimum UMDF version



Wdfusb.h (include Wdfusb.h)


Wdf01000.sys (KMDF);
WUDFx02000.dll (UMDF)



DDI compliance rules

DriverCreate, InternalIoctlReqs, IoctlReqs, KmdfIrql, KmdfIrql2, ReadReqs, SyncReqSend, UsbKmdfIrql, UsbKmdfIrql2

See also




Send comments about this topic to Microsoft

© 2015 Microsoft