Windows apps
Collapse the table of content
Expand the table of content
Information
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.

InitOnceInitialize function

Initializes a one-time initialization structure.

Syntax


VOID WINAPI InitOnceInitialize(
  _Out_ PINIT_ONCE InitOnce
);

Parameters

InitOnce [out]

A pointer to the one-time initialization structure.

Return value

This function does not return a value.

Remarks

The InitOnceInitialize function is used to initialize a one-time initialization structure dynamically. To initialize the structure statically, assign the constant INIT_ONCE_STATIC_INIT to the structure variable.

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.

Examples

The following example calls InitOnceInitialize to initialize the one-time initialization structure named InitOnce. Alternatively, the structure can be declared as a global variable as shown in Using One-Time Initialization.



//Requires Windows Vista, Windows Server 2008 or later
#define _WIN32_WINNT 0x0600

#include <windows.h>

BOOL StartInitialization()
{
    INIT_ONCE InitOnce;

    InitOnceInitialize(&InitOnce);

    //...
    return TRUE;
}


Requirements

Minimum supported client

Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8

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

InitOnceExecuteOnce
One-Time Initialization
Synchronization Functions

 

 

Show:
© 2017 Microsoft