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.

InitOnceExecuteOnce function

Executes the specified function successfully one time. No other threads that specify the same one-time initialization structure can execute the specified function while it is being executed by the current thread.


BOOL WINAPI InitOnceExecuteOnce(
  _Inout_     PINIT_ONCE    InitOnce,
  _In_        PINIT_ONCE_FN InitFn,
  _Inout_opt_ PVOID         Parameter,
  _Out_opt_   LPVOID        *Context


InitOnce [in, out]

A pointer to the one-time initialization structure.

InitFn [in]

A pointer to an application-defined InitOnceCallback function.

Parameter [in, out, optional]

A parameter to be passed to the callback function.

Context [out, optional]

A parameter that receives 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 the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


This function is used for synchronous one-time initialization. For asynchronous one-time initialization, use the InitOnceBeginInitialize function with the INIT_ONCE_ASYNC flag.

Only one thread at a time can execute the callback function specified by InitFn. Other threads that specify the same one-time initialization structure block until the callback finishes.

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]

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



© 2017 Microsoft