InitOnceBeginInitialize function (synchapi.h)

Begins one-time initialization.


BOOL InitOnceBeginInitialize(
  [in, out]       LPINIT_ONCE lpInitOnce,
  [in]            DWORD       dwFlags,
  [out]           PBOOL       fPending,
  [out, optional] LPVOID      *lpContext


[in, out] lpInitOnce

A pointer to the one-time initialization structure.

[in] dwFlags

This parameter can have a value of 0, or one or more of the following flags.

Value Meaning
Enables multiple initialization attempts to execute in parallel. If this flag is used, subsequent calls to this function will fail unless this flag is also specified.
This function call does not begin initialization. The return value indicates whether initialization has already completed. If the function returns TRUE, the lpContext parameter receives the data.

[out] fPending

If the function succeeds, this parameter indicates the current initialization status.

If this parameter is TRUE and dwFlags contains INIT_ONCE_CHECK_ONLY, the initialization is pending and the context data is invalid.

If this parameter is FALSE, initialization has already completed and the caller can retrieve the context data from the lpContext parameter.

If this parameter is TRUE and dwFlags does not contain INIT_ONCE_CHECK_ONLY, initialization has been started and the caller can perform the initialization tasks.

[out, optional] lpContext

An optional parameter that receives the data stored with the one-time initialization structure upon success. The low-order INIT_ONCE_CTX_RESERVED_BITS bits of the data are always zero.

Return value

If INIT_ONCE_CHECK_ONLY is not specified and the function succeeds, the return value is TRUE.

If INIT_ONCE_CHECK_ONLY is specified and initialization has completed, the return value is TRUE.

Otherwise, the return value is FALSE.

To get extended error information, call GetLastError.


This function can be used for either synchronous or asynchronous one-time initialization. For asynchronous one-time initialization, use the INIT_ONCE_ASYNC flag. To specify a callback function to execute during synchronous one-time initialization, see the InitOnceExecuteOnce function.

If this function succeeds, the thread can create a synchronization object and specify in the lpContext parameter of the InitOnceComplete function.

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

A one-time initialization object cannot be moved or copied. The process must not modify the initialization object, and must instead treat it as logically opaque. Only use the one-time initialization functions to manage one-time initialization objects.


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


Requirement Value
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header synchapi.h (include Windows.h on Windows 7, Windows Server 2008 Windows Server 2008 R2)
Library Kernel32.lib
DLL Kernel32.dll

See also



One-Time Initialization

Synchronization Functions