FltSetStreamHandleContext function

Download EaseFilter Filter Driver SDK Setup File
Download EaseFilter Filter Driver SDK Zip File

The FltSetStreamHandleContext routine sets a context for a stream handle.


NTSTATUS FLTAPI FltSetStreamHandleContext(
  PFLT_INSTANCE             Instance,
  PFILE_OBJECT              FileObject,
  PFLT_CONTEXT              NewContext,
  PFLT_CONTEXT              *OldContext



An opaque instance pointer for the minifilter driver instance whose context is to be inserted into, removed from, or replaced in the list of contexts attached to the stream handle.


A pointer to a file object for the file stream.


A flag that specifies details of the operation to be performed. This parameter must be one of the following:


If a context is already set for this Instance, replace it with NewContext. Otherwise, insert NewContext into the list of contexts for the stream handle.


If a context is already set for this Instance, return STATUS_FLT_CONTEXT_ALREADY_DEFINED. Otherwise, insert NewContext into the list of contexts for the stream handle.


A pointer to the new context to be set for the stream handle. This parameter is required and cannot be NULL.


A pointer to a caller-allocated variable that receives the address of the existing stream handle context for the Instance parameter. This parameter is optional and can be NULL. (For more information about this parameter, see the following Remarks section.)

Return value

The FltSetStreamHandleContext routine returns STATUS_SUCCESS or an appropriate NTSTATUS value such as one of the following:

Return code Description
If FLT_SET_CONTEXT_KEEP_IF_EXISTS was specified for Operation, this error code indicates that a context is already attached to the stream handle.
The context pointed to by the NewContext parameter is already linked to an object. In other words, this error code indicates that NewContext is already in use due to a successful prior call of a FltSetXxxContext routine.
The specified Instance is being torn down. This is an error code.
One of the following:
  • The NewContext parameter does not point to a valid stream handle context.
  • An invalid value was specified for Operation.
The file system does not support per-stream contexts for this file stream. This is an error code.


The FltSetStreamHandleContext routine adds, removes, or replaces a context for a minifilter driver instance on a stream handle. A minifilter driver can attach one context per minifilter driver instance to the stream handle.

A successful call to FltSetStreamHandleContext increments the reference count on NewContext. When the context pointed to by NewContext is no longer needed, the minifilter must call FltReleaseContext to decrement its reference count.

If FltSetStreamHandleContext fails, the reference count remains unchanged. In this case, the filter calling FltSetStreamHandleContext must call FltReleaseContext for the NewContext object that was allocated and referenced in FltAllocateContext. If FltSetStreamHandleContext fails and if the OldContext parameter is not NULL and does not point to NULL_CONTEXT then OldContext is a referenced pointer to the context currently associated with the transaction. The filter calling FltSetStreamHandleContext must call FltReleaseContext for OldContext as well.

Note that the OldContext pointer returned by FltSetStreamHandleContext must also be released by calling FltReleaseContext when it is no longer needed. For more information, see Setting Contexts and Releasing Contexts.

Also note that FltSetStreamHandleContext cannot be called on an unopened FileObject. Hence FltSetStreamHandleContext cannot be called from a pre-create callback for a stream because the stream has not been opened at that point. A minifilter can, however, allocate and set up the stream handle context in the pre-create callback, pass it to the post-create callback using the completion context parameter and set the stream handle context on the stream in the post-create callback.

To get a stream handle context, call FltGetStreamHandleContext.

To allocate a new context, call FltAllocateContext.

To delete a stream handle context, call FltDeleteStreamHandleContext or FltDeleteContext.

For more information about context reference counting, see Referencing Contexts.


Minimum supported client Available and supported in Microsoft Windows 2000 Update Rollup 1 for SP4, Windows XP SP2, Windows Server 2003 SP1, and later operating systems. Not available nor supported on Windows 2000 SP4 and earlier operating systems.
Target Platform Universal
Header fltkernel.h (include Fltkernel.h)
Library Fltmgr.lib
DLL Fltmgr.sys