Win32 API 日本語リファレンス
ホームSystem.LibraryLoader › FindResourceExA

FindResourceExA

関数
言語を指定してリソースをANSI名で検索する。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HRSRC FindResourceExA(
    HMODULE hModule,   // optional
    LPCSTR lpType,
    LPCSTR lpName,
    WORD wLanguage
);

パラメーター

名前方向
hModuleHMODULEinoptional
lpTypeLPCSTRin
lpNameLPCSTRin
wLanguageWORDin

戻り値の型: HRSRC

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HRSRC FindResourceExA(
    HMODULE hModule,   // optional
    LPCSTR lpType,
    LPCSTR lpName,
    WORD wLanguage
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindResourceExA(
    IntPtr hModule,   // HMODULE optional
    [MarshalAs(UnmanagedType.LPStr)] string lpType,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string lpName,   // LPCSTR
    ushort wLanguage   // WORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindResourceExA(
    hModule As IntPtr,   ' HMODULE optional
    <MarshalAs(UnmanagedType.LPStr)> lpType As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpName As String,   ' LPCSTR
    wLanguage As UShort   ' WORD
) As IntPtr
End Function
' hModule : HMODULE optional
' lpType : LPCSTR
' lpName : LPCSTR
' wLanguage : WORD
Declare PtrSafe Function FindResourceExA Lib "kernel32" ( _
    ByVal hModule As LongPtr, _
    ByVal lpType As String, _
    ByVal lpName As String, _
    ByVal wLanguage As Integer) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindResourceExA = ctypes.windll.kernel32.FindResourceExA
FindResourceExA.restype = ctypes.c_void_p
FindResourceExA.argtypes = [
    wintypes.HANDLE,  # hModule : HMODULE optional
    wintypes.LPCSTR,  # lpType : LPCSTR
    wintypes.LPCSTR,  # lpName : LPCSTR
    ctypes.c_ushort,  # wLanguage : WORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FindResourceExA = Fiddle::Function.new(
  lib['FindResourceExA'],
  [
    Fiddle::TYPE_VOIDP,  # hModule : HMODULE optional
    Fiddle::TYPE_VOIDP,  # lpType : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpName : LPCSTR
    -Fiddle::TYPE_SHORT,  # wLanguage : WORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn FindResourceExA(
        hModule: *mut core::ffi::c_void,  // HMODULE optional
        lpType: *const u8,  // LPCSTR
        lpName: *const u8,  // LPCSTR
        wLanguage: u16  // WORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindResourceExA(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string lpType, [MarshalAs(UnmanagedType.LPStr)] string lpName, ushort wLanguage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindResourceExA' -Namespace Win32 -PassThru
# $api::FindResourceExA(hModule, lpType, lpName, wLanguage)
#uselib "KERNEL32.dll"
#func global FindResourceExA "FindResourceExA" sptr, sptr, sptr, sptr
; FindResourceExA hModule, lpType, lpName, wLanguage   ; 戻り値は stat
; hModule : HMODULE optional -> "sptr"
; lpType : LPCSTR -> "sptr"
; lpName : LPCSTR -> "sptr"
; wLanguage : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global FindResourceExA "FindResourceExA" sptr, str, str, int
; res = FindResourceExA(hModule, lpType, lpName, wLanguage)
; hModule : HMODULE optional -> "sptr"
; lpType : LPCSTR -> "str"
; lpName : LPCSTR -> "str"
; wLanguage : WORD -> "int"
; HRSRC FindResourceExA(HMODULE hModule, LPCSTR lpType, LPCSTR lpName, WORD wLanguage)
#uselib "KERNEL32.dll"
#cfunc global FindResourceExA "FindResourceExA" intptr, str, str, int
; res = FindResourceExA(hModule, lpType, lpName, wLanguage)
; hModule : HMODULE optional -> "intptr"
; lpType : LPCSTR -> "str"
; lpName : LPCSTR -> "str"
; wLanguage : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindResourceExA = kernel32.NewProc("FindResourceExA")
)

// hModule (HMODULE optional), lpType (LPCSTR), lpName (LPCSTR), wLanguage (WORD)
r1, _, err := procFindResourceExA.Call(
	uintptr(hModule),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpType))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpName))),
	uintptr(wLanguage),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRSRC
function FindResourceExA(
  hModule: THandle;   // HMODULE optional
  lpType: PAnsiChar;   // LPCSTR
  lpName: PAnsiChar;   // LPCSTR
  wLanguage: Word   // WORD
): THandle; stdcall;
  external 'KERNEL32.dll' name 'FindResourceExA';
result := DllCall("KERNEL32\FindResourceExA"
    , "Ptr", hModule   ; HMODULE optional
    , "AStr", lpType   ; LPCSTR
    , "AStr", lpName   ; LPCSTR
    , "UShort", wLanguage   ; WORD
    , "Ptr")   ; return: HRSRC
●FindResourceExA(hModule, lpType, lpName, wLanguage) = DLL("KERNEL32.dll", "void* FindResourceExA(void*, char*, char*, int)")
# 呼び出し: FindResourceExA(hModule, lpType, lpName, wLanguage)
# hModule : HMODULE optional -> "void*"
# lpType : LPCSTR -> "char*"
# lpName : LPCSTR -> "char*"
# wLanguage : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。