ホーム › System.LibraryLoader › GetProcAddress
GetProcAddress
関数DLLからエクスポート関数のアドレスを取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
FARPROC GetProcAddress(
HMODULE hModule,
LPCSTR lpProcName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hModule | HMODULE | in |
| lpProcName | LPCSTR | in |
戻り値の型: FARPROC
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
FARPROC GetProcAddress(
HMODULE hModule,
LPCSTR lpProcName
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr GetProcAddress(
IntPtr hModule, // HMODULE
[MarshalAs(UnmanagedType.LPStr)] string lpProcName // LPCSTR
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetProcAddress(
hModule As IntPtr, ' HMODULE
<MarshalAs(UnmanagedType.LPStr)> lpProcName As String ' LPCSTR
) As IntPtr
End Function' hModule : HMODULE
' lpProcName : LPCSTR
Declare PtrSafe Function GetProcAddress Lib "kernel32" ( _
ByVal hModule As LongPtr, _
ByVal lpProcName As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetProcAddress = ctypes.windll.kernel32.GetProcAddress
GetProcAddress.restype = ctypes.c_void_p
GetProcAddress.argtypes = [
wintypes.HANDLE, # hModule : HMODULE
wintypes.LPCSTR, # lpProcName : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetProcAddress = Fiddle::Function.new(
lib['GetProcAddress'],
[
Fiddle::TYPE_VOIDP, # hModule : HMODULE
Fiddle::TYPE_VOIDP, # lpProcName : LPCSTR
],
Fiddle::TYPE_VOIDP)#[link(name = "kernel32")]
extern "system" {
fn GetProcAddress(
hModule: *mut core::ffi::c_void, // HMODULE
lpProcName: *const u8 // LPCSTR
) -> *const core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetProcAddress' -Namespace Win32 -PassThru
# $api::GetProcAddress(hModule, lpProcName)#uselib "KERNEL32.dll"
#func global GetProcAddress "GetProcAddress" sptr, sptr
; GetProcAddress hModule, lpProcName ; 戻り値は stat
; hModule : HMODULE -> "sptr"
; lpProcName : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetProcAddress "GetProcAddress" sptr, str
; res = GetProcAddress(hModule, lpProcName)
; hModule : HMODULE -> "sptr"
; lpProcName : LPCSTR -> "str"; FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
#uselib "KERNEL32.dll"
#cfunc global GetProcAddress "GetProcAddress" intptr, str
; res = GetProcAddress(hModule, lpProcName)
; hModule : HMODULE -> "intptr"
; lpProcName : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetProcAddress = kernel32.NewProc("GetProcAddress")
)
// hModule (HMODULE), lpProcName (LPCSTR)
r1, _, err := procGetProcAddress.Call(
uintptr(hModule),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpProcName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // FARPROCfunction GetProcAddress(
hModule: THandle; // HMODULE
lpProcName: PAnsiChar // LPCSTR
): Pointer; stdcall;
external 'KERNEL32.dll' name 'GetProcAddress';result := DllCall("KERNEL32\GetProcAddress"
, "Ptr", hModule ; HMODULE
, "AStr", lpProcName ; LPCSTR
, "Ptr") ; return: FARPROC●GetProcAddress(hModule, lpProcName) = DLL("KERNEL32.dll", "void* GetProcAddress(void*, char*)")
# 呼び出し: GetProcAddress(hModule, lpProcName)
# hModule : HMODULE -> "void*"
# lpProcName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。