Executes the specified function successfully one time. No other threads that specify the same one-time initialization structure can execute this function while it is being executed by the current thread.
Syntax
BOOL WINAPI InitOnceExecuteOnce(
__inout PINIT_ONCE InitOnce,
__in PINIT_ONCE_FN InitFn,
__inout_opt PVOID Parameter,
__out_opt LPVOID *Context
);
Parameters
- 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]
-
An optional parameter to be passed to the callback function.
- Context [out, optional]
-
A pointer to the data stored with the one-time initialization structure upon success. The low-order INIT_ONCE_CTX_RESERVED_BITS bits of the data must be 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.
Remarks
This function is used for synchronous one-time initialization. For asynchronous one-time initialization, use the InitOnceBeginInitialize function with the INIT_ONCE_ASYNC flag.
To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see
Using the Windows Headers.
Examples
For an example that uses
this function, see
Using One-Time Initialization.
Requirements
Minimum supported client | Windows Vista |
Minimum supported server | Windows Server 2008 |
Header | Winbase.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
See Also
- InitOnceCallback
- InitOnceInitialize
- One-Time Initialization
- Synchronization Functions
Send comments about this topic to Microsoft
Build date: 2/4/2010