Win32 API 日本語リファレンス
ホームDevices.Display › EngFindResource

EngFindResource

関数
読み込んだモジュールからリソースを検索する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll
#include <windows.h>

void* EngFindResource(
    HANDLE h,
    INT iName,
    INT iType,
    DWORD* pulSize
);

パラメーター

名前方向説明
hHANDLEinリソースを含むモジュールへのハンドル。このハンドルは EngLoadModule から取得します。
iNameINTin検索対象のリソースの名前を表す整数識別子です。
iTypeINTin検索対象のリソースの種類を表す整数識別子です。
pulSizeDWORD*outリソースのサイズ(バイト単位)が返される ULONG へのポインターです。

戻り値の型: void*

公式ドキュメント

EngFindResource 関数は、モジュール内のリソースの位置を特定します。

戻り値

戻り値は、指定したリソースのアドレスへのポインターです。エラーが発生した場合、関数は NULL を返します。

解説(Remarks)

リソースの位置の特定に成功した場合、そのサイズが pulSize に返されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// GDI32.dll
#include <windows.h>

void* EngFindResource(
    HANDLE h,
    INT iName,
    INT iType,
    DWORD* pulSize
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr EngFindResource(
    IntPtr h,   // HANDLE
    int iName,   // INT
    int iType,   // INT
    out uint pulSize   // DWORD* out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function EngFindResource(
    h As IntPtr,   ' HANDLE
    iName As Integer,   ' INT
    iType As Integer,   ' INT
    <Out> ByRef pulSize As UInteger   ' DWORD* out
) As IntPtr
End Function
' h : HANDLE
' iName : INT
' iType : INT
' pulSize : DWORD* out
Declare PtrSafe Function EngFindResource Lib "gdi32" ( _
    ByVal h As LongPtr, _
    ByVal iName As Long, _
    ByVal iType As Long, _
    ByRef pulSize As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EngFindResource = ctypes.windll.gdi32.EngFindResource
EngFindResource.restype = ctypes.c_void_p
EngFindResource.argtypes = [
    wintypes.HANDLE,  # h : HANDLE
    ctypes.c_int,  # iName : INT
    ctypes.c_int,  # iType : INT
    ctypes.POINTER(wintypes.DWORD),  # pulSize : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
EngFindResource = Fiddle::Function.new(
  lib['EngFindResource'],
  [
    Fiddle::TYPE_VOIDP,  # h : HANDLE
    Fiddle::TYPE_INT,  # iName : INT
    Fiddle::TYPE_INT,  # iType : INT
    Fiddle::TYPE_VOIDP,  # pulSize : DWORD* out
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn EngFindResource(
        h: *mut core::ffi::c_void,  // HANDLE
        iName: i32,  // INT
        iType: i32,  // INT
        pulSize: *mut u32  // DWORD* out
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr EngFindResource(IntPtr h, int iName, int iType, out uint pulSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_EngFindResource' -Namespace Win32 -PassThru
# $api::EngFindResource(h, iName, iType, pulSize)
#uselib "GDI32.dll"
#func global EngFindResource "EngFindResource" sptr, sptr, sptr, sptr
; EngFindResource h, iName, iType, varptr(pulSize)   ; 戻り値は stat
; h : HANDLE -> "sptr"
; iName : INT -> "sptr"
; iType : INT -> "sptr"
; pulSize : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global EngFindResource "EngFindResource" sptr, int, int, var
; res = EngFindResource(h, iName, iType, pulSize)
; h : HANDLE -> "sptr"
; iName : INT -> "int"
; iType : INT -> "int"
; pulSize : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* EngFindResource(HANDLE h, INT iName, INT iType, DWORD* pulSize)
#uselib "GDI32.dll"
#cfunc global EngFindResource "EngFindResource" intptr, int, int, var
; res = EngFindResource(h, iName, iType, pulSize)
; h : HANDLE -> "intptr"
; iName : INT -> "int"
; iType : INT -> "int"
; pulSize : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procEngFindResource = gdi32.NewProc("EngFindResource")
)

// h (HANDLE), iName (INT), iType (INT), pulSize (DWORD* out)
r1, _, err := procEngFindResource.Call(
	uintptr(h),
	uintptr(iName),
	uintptr(iType),
	uintptr(pulSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function EngFindResource(
  h: THandle;   // HANDLE
  iName: Integer;   // INT
  iType: Integer;   // INT
  pulSize: Pointer   // DWORD* out
): Pointer; stdcall;
  external 'GDI32.dll' name 'EngFindResource';
result := DllCall("GDI32\EngFindResource"
    , "Ptr", h   ; HANDLE
    , "Int", iName   ; INT
    , "Int", iType   ; INT
    , "Ptr", pulSize   ; DWORD* out
    , "Ptr")   ; return: void*
●EngFindResource(h, iName, iType, pulSize) = DLL("GDI32.dll", "void* EngFindResource(void*, int, int, void*)")
# 呼び出し: EngFindResource(h, iName, iType, pulSize)
# h : HANDLE -> "void*"
# iName : INT -> "int"
# iType : INT -> "int"
# pulSize : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn EngFindResource(
    h: ?*anyopaque, // HANDLE
    iName: i32, // INT
    iType: i32, // INT
    pulSize: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc EngFindResource(
    h: pointer,  # HANDLE
    iName: int32,  # INT
    iType: int32,  # INT
    pulSize: ptr uint32  # DWORD* out
): pointer {.importc: "EngFindResource", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
void* EngFindResource(
    void* h,   // HANDLE
    int iName,   // INT
    int iType,   // INT
    uint* pulSize   // DWORD* out
);
ccall((:EngFindResource, "GDI32.dll"), stdcall, Ptr{Cvoid},
      (Ptr{Cvoid}, Int32, Int32, Ptr{UInt32}),
      h, iName, iType, pulSize)
# h : HANDLE -> Ptr{Cvoid}
# iName : INT -> Int32
# iType : INT -> Int32
# pulSize : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* EngFindResource(
    void* h,
    int32_t iName,
    int32_t iType,
    uint32_t* pulSize);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.EngFindResource(h, iName, iType, pulSize)
-- h : HANDLE
-- iName : INT
-- iType : INT
-- pulSize : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const EngFindResource = lib.func('__stdcall', 'EngFindResource', 'void *', ['void *', 'int32_t', 'int32_t', 'uint32_t *']);
// EngFindResource(h, iName, iType, pulSize)
// h : HANDLE -> 'void *'
// iName : INT -> 'int32_t'
// iType : INT -> 'int32_t'
// pulSize : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  EngFindResource: { parameters: ["pointer", "i32", "i32", "pointer"], result: "pointer" },
});
// lib.symbols.EngFindResource(h, iName, iType, pulSize)
// h : HANDLE -> "pointer"
// iName : INT -> "i32"
// iType : INT -> "i32"
// pulSize : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* EngFindResource(
    void* h,
    int32_t iName,
    int32_t iType,
    uint32_t* pulSize);
C, "GDI32.dll");
// $ffi->EngFindResource(h, iName, iType, pulSize);
// h : HANDLE
// iName : INT
// iType : INT
// pulSize : DWORD* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Gdi32 extends StdCallLibrary {
    Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
    Pointer EngFindResource(
        Pointer h,   // HANDLE
        int iName,   // INT
        int iType,   // INT
        IntByReference pulSize   // DWORD* out
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun EngFindResource = EngFindResource(
    h : Void*,   # HANDLE
    iName : Int32,   # INT
    iType : Int32,   # INT
    pulSize : UInt32*   # DWORD* out
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef EngFindResourceNative = Pointer<Void> Function(Pointer<Void>, Int32, Int32, Pointer<Uint32>);
typedef EngFindResourceDart = Pointer<Void> Function(Pointer<Void>, int, int, Pointer<Uint32>);
final EngFindResource = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<EngFindResourceNative, EngFindResourceDart>('EngFindResource');
// h : HANDLE -> Pointer<Void>
// iName : INT -> Int32
// iType : INT -> Int32
// pulSize : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function EngFindResource(
  h: THandle;   // HANDLE
  iName: Integer;   // INT
  iType: Integer;   // INT
  pulSize: Pointer   // DWORD* out
): Pointer; stdcall;
  external 'GDI32.dll' name 'EngFindResource';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "EngFindResource"
  c_EngFindResource :: Ptr () -> Int32 -> Int32 -> Ptr Word32 -> IO (Ptr ())
-- h : HANDLE -> Ptr ()
-- iName : INT -> Int32
-- iType : INT -> Int32
-- pulSize : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let engfindresource =
  foreign "EngFindResource"
    ((ptr void) @-> int32_t @-> int32_t @-> (ptr uint32_t) @-> returning (ptr void))
(* h : HANDLE -> (ptr void) *)
(* iName : INT -> int32_t *)
(* iType : INT -> int32_t *)
(* pulSize : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("EngFindResource" eng-find-resource :convention :stdcall) :pointer
  (h :pointer)   ; HANDLE
  (i-name :int32)   ; INT
  (i-type :int32)   ; INT
  (pul-size :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $EngFindResource = Win32::API::More->new('GDI32',
    'LPVOID EngFindResource(HANDLE h, int iName, int iType, LPVOID pulSize)');
# my $ret = $EngFindResource->Call($h, $iName, $iType, $pulSize);
# h : HANDLE -> HANDLE
# iName : INT -> int
# iType : INT -> int
# pulSize : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目