BytesWritten in WdfUsbTargetPipeWriteSynchronously

I use the following code to write to an Interrupt pipe:

***

//* write a command to the hardware *
WDF_REQUEST_SEND_OPTIONS_INIT(&sendop, 0);
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&sendop, WDF_REL_TIMEOUT_IN_SEC(OP_TIMEOUT));
bytesWritten = 0;
status = WdfUsbTargetPipeWriteSynchronously(
devCtx->UsbInterruptOutPipe,
0,
&sendop,
&memDin,
&bytesWritten);
if(!NT_SUCCESS(status)) {
KdPrint((_DN “WdfUsbTargetPipeWriteSynchronously FAILED! (0x%08x)\n”, status));
WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
return;
} else {
KdPrint((_DN “Wrote %lu bytes\n”, bytesWritten));
}

***

On return, bytesWritten is usually some outrageous value, such as 3141533696. I’m pretty sure I’m doing this like the example in the WDK shows, and I’m pretty sure I have the write formatting in the KdPrint statement, so I don’t see how else I could be messing this one up.
FWIW, I see the same results in the equivalent read function.

Is there a problem in the framework or am I missing some obvious bug?

jorj

I would assume bytesWritten is declared as a ULONG…barring that, KMDF will set it to zero on entry into the write/read synchronous function and then will blindly copy the value from the URB (the TransferBufferLength field) after it has sent the request. Perhaps you are modifying the value after the call. One thing you can do is set a break on write breakpoint (ba w4

) before making the call and seeing where the value is being set.

d