WdfMemoryCopyToBuffer function (wdfmemory.h)
[Applies to KMDF and UMDF]
The WdfMemoryCopyToBuffer method copies the contents of a specified memory object's buffer into a specified destination buffer.
Syntax
NTSTATUS WdfMemoryCopyToBuffer(
[in] WDFMEMORY SourceMemory,
[in] size_t SourceOffset,
[out] PVOID Buffer,
[in] size_t NumBytesToCopyTo
);
Parameters
[in] SourceMemory
A handle to a framework memory object that represents the source buffer.
[in] SourceOffset
An offset, in bytes, from the beginning of the source buffer. The copy operation begins at the specified offset in the source buffer.
[out] Buffer
A pointer to a destination buffer.
[in] NumBytesToCopyTo
The number of bytes to copy from the source buffer to the destination buffer. This value must not be greater than the size of the source buffer.
Return value
WdfMemoryCopyToBuffer returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:
Return code | Description |
---|---|
|
An invalid parameter was detected. |
|
The byte offset that the SourceOffset parameter specified was too large, or the NumBytesToCopyTo parameter was greater than the size of the source buffer. |
This method also might return other NTSTATUS values.
A bug check occurs if the driver supplies an invalid object handle.
Remarks
The framework does not allow the driver to copy more bytes than the source buffer that the SourceMemory parameter specifies can contain.
For more information about framework memory objects, see Using Memory Buffers.
If the source or destination buffer was allocated from the pageable memory pool, the WdfMemoryCopyToBuffer method must be called at IRQL <= APC_LEVEL. Otherwise, the method can be called at any IRQL.
Examples
The following code example allocates a new buffer and copies the contents of a memory object's buffer into the new buffer.
PVOID pOutputBuffer = NULL;
NTSTATUS status = STATUS_SUCCESS;
pOutputBuffer = ExAllocatePoolWithTag(
NonPagedPool,
MY_BUFFER_LENGTH,
MY_POOL_TAG
);
if (pOutputBuffer != NULL){
status = WdfMemoryCopyToBuffer(
outputMemoryHandle,
0,
pOutputBuffer,
MY_BUFFER_LENGTH
);
}
else{
status = STATUS_INSUFFICIENT_RESOURCES;
}
Requirements
Requirement | Value |
---|---|
Target Platform | Universal |
Minimum KMDF version | 1.0 |
Minimum UMDF version | 2.0 |
Header | wdfmemory.h (include Wdf.h) |
Library | Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF) |
IRQL | Any level (see Remarks section) |
DDI compliance rules | BufAfterReqCompletedIntIoctlA(kmdf), BufAfterReqCompletedIoctlA(kmdf), BufAfterReqCompletedReadA(kmdf), BufAfterReqCompletedWriteA(kmdf), DriverCreate(kmdf), MemAfterReqCompletedIntIoctlA(kmdf), MemAfterReqCompletedIoctlA(kmdf), MemAfterReqCompletedReadA(kmdf), MemAfterReqCompletedWriteA(kmdf) |