Crashpad

Namespaces | Macros | Functions
get_function.h File Reference
`#include <windows.h>`

## Namespaces
| crashpad
| The main namespace.
| crashpad::internal
| The internal namespace, not for public use.

## Macros
#define | GET_FUNCTION(library, function)
| Returns a function pointer to a named function in a library without requiring that it be found. More...
#define | GET_FUNCTION_REQUIRED(library, function)
| Returns a function pointer to a named function in a library, requiring that it be found. More...

## Functions
FARPROC | crashpad::internal::GetFunctionInternal (const wchar_t *library, const char *function, bool required)
| Returns a function pointer to a named function in a library. More...
template<typename FunctionType >
FunctionType * | crashpad::internal::GetFunction (const wchar_t *library, const char *function, bool required)
| Returns a function pointer to a named function in a library. More...

## Macro Definition Documentation

## ◆ GET_FUNCTION

#define GET_FUNCTION | ( |  | library,
|  |  | function
| ) |  |

Value:
crashpad::internal::GetFunction<decltype(function)>( \
library, #function, false)

Returns a function pointer to a named function in a library without requiring that it be found.

If the library or function cannot be found, this will return `nullptr`. This macro is intended to be used to access functions that may not be available at runtime.

This macro returns a properly-typed function pointer. It is expected to be used in this way:

static const auto get_named_pipe_client_process_id =
GET_FUNCTION(L"kernel32.dll", ::GetNamedPipeClientProcessId);
if (get_named_pipe_client_process_id) {
BOOL rv = get_named_pipe_client_process_id(pipe, &client_process_id);
}

This accesses library by calling `LoadLibrary()` and is subject to the same restrictions as that function. Notably, it can’t be used from a `DllMain()` entry point.

Parameters

  [in] | library | The library to search in.
  [in] | function | The function to search for. A leading `::` is recommended when a wrapper function of the same name is present.

Returns
  A pointer to the requested function on success, or `nullptr` on failure.

See also
  GET_FUNCTION_REQUIRED

## ◆ GET_FUNCTION_REQUIRED

#define GET_FUNCTION_REQUIRED | ( |  | library,
|  |  | function
| ) |  |

Value:
crashpad::internal::GetFunction<decltype(function)>( \
library, #function, true)

Returns a function pointer to a named function in a library, requiring that it be found.

If the library or function cannot be found, this will trigger a `DCHECK` assertion. This macro is intended to be used to access functions that are always expected to be available at runtime but which are not present in any import library.

This macro returns a properly-typed function pointer. It is expected to be used in this way:

static const auto nt_query_object =
GET_FUNCTION_REQUIRED(L"ntdll.dll", ::NtQueryObject);
NTSTATUS status =
nt_query_object(handle, type, &info, info_length, &return_length);

This accesses library by calling `LoadLibrary()` and is subject to the same restrictions as that function. Notably, it can’t be used from a `DllMain()` entry point.

Parameters

  [in] | library | The library to search in.
  [in] | function | The function to search for. A leading `::` is recommended when a wrapper function of the same name is present.

Returns
  A pointer to the requested function.

See also
  GET_FUNCTION