InitOnceCallback callback function

An application-defined callback function. Specify a pointer to this function when calling the InitOnceExecuteOnce function. The PINIT_ONCE_FN type defines a pointer to this callback function. InitOnceCallback is a placeholder for the application-defined function name.


BOOL CALLBACK InitOnceCallback(
  _Inout_     PINIT_ONCE InitOnce,
  _Inout_opt_ PVOID      Parameter,
  _Out_opt_   PVOID      *Context


InitOnce [in, out]

A pointer to the one-time initialization structure.

Parameter [in, out, optional]

An optional parameter that was passed to the callback function.

Context [out, optional]

The data to be stored with the one-time initialization structure. If Context references a value, the low-order INIT_ONCE_CTX_RESERVED_BITS of the value must be zero. If Context points to a data structure, the data structure must be DWORD-aligned.

Return value

If the function returns TRUE, the block is marked as initialized.

If the function returns FALSE, the block is not marked as initialized and the call to InitOnceExecuteOnce fails. To communicate additional error information, call SetLastError before returning FALSE.


This function can create a synchronization object and return it in the lpContext parameter.

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see Using the Windows Headers.


For an example that uses this function, see Using One-Time Initialization.


Minimum supported client

Windows Vista [desktop apps | UWP apps]

Minimum supported server

Windows Server 2008 [desktop apps | UWP apps]


WinBase.h (include Windows.h)

See also

Synchronization Functions