Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

InitOnceBeginInitialize function

Begins one-time initialization.


BOOL WINAPI InitOnceBeginInitialize(
  _Inout_   LPINIT_ONCE lpInitOnce,
  _In_      DWORD       dwFlags,
  _Out_     PBOOL       fPending,
  _Out_opt_ LPVOID      *lpContext


lpInitOnce [in, out]

A pointer to the one-time initialization structure.

dwFlags [in]

This parameter can be one or more of the following flags.


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.


fPending [out]

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.

lpContext [out, optional]

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.


Minimum supported client

Windows Vista [desktop apps | UWP apps]

Minimum supported server

Windows Server 2008 [desktop apps | UWP apps]

Minimum supported phone

Windows Phone 8


WinBase.h on Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2 (include Windows.h);
Synchapi.h on Windows 8 and Windows Server 2012





See also

One-Time Initialization
Synchronization Functions



© 2018 Microsoft