InitOnceBeginInitialize function

Begins one-time initialization.

Syntax


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

Parameters

lpInitOnce [in, out]

A pointer to the one-time initialization structure.

dwFlags [in]

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

ValueMeaning
INIT_ONCE_ASYNC
0x00000002UL

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.

INIT_ONCE_CHECK_ONLY
0x00000001UL

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.

Remarks

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.

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

Examples

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

Requirements

Minimum supported client

Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

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

Library

Kernel32.lib

DLL

Kernel32.dll

See also

InitOnceComplete
InitOnceExecuteOnce
One-Time Initialization
Synchronization Functions