Reactos
at master 67 lines 1.8 kB view raw
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*******************************************************************************/ 37typedef int (__cdecl* proc_address_type)(); 38 39extern "C" 40DECLSPEC_GUARD_SUPPRESS 41proc_address_type __cdecl _getdllprocaddr( 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}