Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

GetProcAddress function (libloaderapi.h)

Feedback

In this article

Retrieves the address of an exported function (also known as a procedure) or variable from the specified dynamic-link library (DLL).

Syntax

FARPROC GetProcAddress(  [in] HMODULE hModule,  [in] LPCSTR  lpProcName);

Parameters

[in] hModule

A handle to the DLL module that contains the function or variable. TheLoadLibrary,LoadLibraryEx,LoadPackagedLibrary, orGetModuleHandle function returns this handle.

TheGetProcAddress function does not retrieve addresses from modules that were loaded using theLOAD_LIBRARY_AS_DATAFILE flag. For more information, seeLoadLibraryEx.

[in] lpProcName

The function or variable name, or the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.

Return value

If the function succeeds, the return value is the address of the exported function or variable.

If the function fails, the return value is NULL. To get extended error information, callGetLastError.

Remarks

The spelling and case of a function name pointed to bylpProcName must be identical to that in theEXPORTS statement of the source DLL's module-definition (.def) file. The exported names of functions may differ from the names you use when calling these functions in your code. This difference is hidden by macros used in the SDK header files. For more information, seeConventions for Function Prototypes.

ThelpProcName parameter can identify the DLL function by specifying an ordinal value associated with the function in theEXPORTS statement.GetProcAddress verifies that the specified ordinal is in the range 1 through the highest ordinal value exported in the .def file. The function then uses the ordinal as an index to read the function's address from a function table.

If the .def file does not number the functions consecutively from 1 toN (whereN is the number of exported functions), an error can occur whereGetProcAddress returns an invalid, non-NULL address, even though there is no function with the specified ordinal.

If the function might not exist in the DLL module—for example, if the function is available only on Windows Vista but the application might be running on Windows XP—specify the function by name rather than by ordinal value and design your application to handle the case when the function is not available, as shown in the following code fragment.

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);// Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.   PGNSI pGNSI;   SYSTEM_INFO si;   ZeroMemory(&si, sizeof(SYSTEM_INFO));      pGNSI = (PGNSI) GetProcAddress(      GetModuleHandle(TEXT("kernel32.dll")),       "GetNativeSystemInfo");   if(NULL != pGNSI)   {      pGNSI(&si);   }   else    {       GetSystemInfo(&si);   }

For the complete example that contains this code fragment, seeGetting the System Version.

Examples

For an example, seeUsing Run-Time Dynamic Linking.

Requirements

RequirementValue
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headerlibloaderapi.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See also

Dynamic-Link Library Functions

FreeLibrary

GetModuleHandle

LoadLibrary

LoadLibraryEx

LoadPackagedLibrary

Run-Time Dynamic Linking

Vertdll APIs available in VBS enclaves


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?