Determines whether the specified function in a delay-loaded DLL is available on the system.
BOOL QueryOptionalDelayLoadedAPI( HMODULE hParentModule, LPCSTR lpDllName, LPCSTR lpProcName, DWORD Reserved );
A handle to the calling module. Desktop applications can use the GetModuleHandle or GetModuleHandleEx function to get this handle. Windows Store apps should set this parameter to
The file name of the delay-loaded DLL that exports the specified function. This parameter is case-insensitive.
Windows Store apps should specify API sets, rather than monolithic DLLs. For example, api-ms-win-core-memory-l1-1-1.dll, rather than kernel32.dll.
The name of the function to query. This parameter is case-sensitive.
This parameter is reserved and must be zero (0).
TRUE if the specified function is available on the system. If the specified function is not available on the system, this function returns FALSE. To get extended error information, call GetLastError.
A delay-loaded DLL is statically linked but not actually loaded into memory until the running application references a symbol exported by that DLL. Applications often delay load DLLs that contain functions the application might call only rarely or not at all, because the DLL is only loaded when it is needed instead of being loaded at application startup like other statically linked DLLs. This helps improve application performance, especially during initialization. A delay-load DLL is specified at link time with the /DELAYLOAD (Delay Load Import) linker option.
Applications that target multiple versions of Windows or multiple Windows device families also rely on delay-loaded DLLs to make visible extra features when they are available.
A desktop application can use delayed loading as an alternative to runtime dynamic linking that uses LoadLibrary or LoadLibraryEx to load a DLL and GetProcAddress to get a pointer to a function. A Windows Store app cannot use LoadLibrary or LoadLibraryEx, so to get the benefits to runtime dynamic linking, a Windows Store app must use the delayed loading mechanism.
To check whether a function in a delay-loaded DLL is available on the system, the application calls QueryOptionalDelayLoadedAPI with the specified function. If QueryOptionalDelayLoadedAPI succeeds, the application can safely call the specified function.
The following example shows how to use QueryOptionalDelayLoadedAPI to determine whether the VirtualAllocEx function is available on the system.
#include <windows.h> #include <libloaderapi2.h>
|Windows version||Windows 10 [desktop apps | UWP apps] Windows Server 2016 [desktop apps | UWP apps]|