Tao.Platform.Windows SDK Documentation

Kernel.GetProcAddress Method 

The GetProcAddress function retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).

[Visual Basic]
Public Shared Function GetProcAddress( _
   ByVal module As IntPtr, _
   ByVal processName As String _
) As IntPtr
[C#]
public static IntPtr GetProcAddress(
   IntPtr module,
   string processName
);

Parameters

module
Handle to the DLL module that contains the function or variable. The LoadLibrary or GetModuleHandle function returns this handle.
processName
Pointer to a null-terminated string that specifies 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 (IntPtr.Zero). To get extended error information, call GetLastWin32Error.

Remarks

The spelling and case of a function name pointed to by processName must be identical to that in the EXPORTS 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.

The processName parameter can identify the DLL function by specifying an ordinal value associated with the function in the EXPORTS 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 to N (where N is the number of exported functions), an error can occur where GetProcAddress returns an invalid, non-NULL address, even though there is no function with the specified ordinal.

In cases where the function may not exist, the function should be specified by name rather than by ordinal value.

See Also

Kernel Class | Tao.Platform.Windows Namespace | FreeLibrary | GetModuleHandle | LoadLibrary