ReactOS 0.4.16-dev-959-g2ec3a19
getproc.cpp
Go to the documentation of this file.
1/***
2*getproc.c - Get the address of a procedure in a DLL.
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* defines _getdllprocadd() - gets a procedure address by name or
8* ordinal
9*
10*******************************************************************************/
11
12#include <corecrt_internal.h>
13
14#define _CRT_ENABLE_OBSOLETE_LOADLIBRARY_FUNCTIONS
15
16#include <process.h>
17
18/***
19*int (*)() _getdllprocaddr(handle, name, ordinal) - Get the address of a
20* DLL procedure specified by name or ordinal
21*
22*Purpose:
23*
24*Entry:
25* int handle - a DLL handle from _loaddll
26* char * name - Name of the procedure, or nullptr to get by ordinal
27* int ordinal - Ordinal of the procedure, or -1 to get by name
28*
29*
30*Exit:
31* returns a pointer to the procedure if found
32* returns nullptr if not found
33*
34*Exceptions:
35*
36*******************************************************************************/
38
39extern "C"
42 intptr_t const module_handle_value,
43 char* const procedure_name,
44 intptr_t const ordinal
45 )
46{
47 HMODULE const module_handle = reinterpret_cast<HMODULE>(module_handle_value);
48 if (procedure_name == nullptr)
49 {
50 if (ordinal <= 65535)
51 {
52 char* const ordinal_as_string = reinterpret_cast<char*>(ordinal);
53 return reinterpret_cast<proc_address_type>(
54 GetProcAddress(module_handle, ordinal_as_string));
55 }
56 }
57 else
58 {
59 if (ordinal == static_cast<intptr_t>(-1))
60 {
61 return reinterpret_cast<proc_address_type>(
62 GetProcAddress(module_handle, procedure_name));
63 }
64 }
65
66 return nullptr;
67}
#define __cdecl
Definition: accygwin.h:79
#define GetProcAddress(x, y)
Definition: compat.h:753
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int(__cdecl * proc_address_type)()
Definition: getproc.cpp:37
DECLSPEC_GUARD_SUPPRESS proc_address_type __cdecl _getdllprocaddr(intptr_t const module_handle_value, char *const procedure_name, intptr_t const ordinal)
Definition: getproc.cpp:41
#define DECLSPEC_GUARD_SUPPRESS
Definition: ntbasedef.h:233
int intptr_t
Definition: vcruntime.h:134