Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › LoadImageA

LoadImageA

関数
アイコン・カーソル・ビットマップを読み込む(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HANDLE LoadImageA(
    HINSTANCE hInst,   // optional
    LPCSTR name,
    GDI_IMAGE_TYPE type,
    INT cx,
    INT cy,
    IMAGE_FLAGS fuLoad
);

パラメーター

名前方向
hInstHINSTANCEinoptional
nameLPCSTRin
typeGDI_IMAGE_TYPEin
cxINTin
cyINTin
fuLoadIMAGE_FLAGSin

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE LoadImageA(
    HINSTANCE hInst,   // optional
    LPCSTR name,
    GDI_IMAGE_TYPE type,
    INT cx,
    INT cy,
    IMAGE_FLAGS fuLoad
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr LoadImageA(
    IntPtr hInst,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPStr)] string name,   // LPCSTR
    uint type,   // GDI_IMAGE_TYPE
    int cx,   // INT
    int cy,   // INT
    uint fuLoad   // IMAGE_FLAGS
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadImageA(
    hInst As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPStr)> name As String,   ' LPCSTR
    type As UInteger,   ' GDI_IMAGE_TYPE
    cx As Integer,   ' INT
    cy As Integer,   ' INT
    fuLoad As UInteger   ' IMAGE_FLAGS
) As IntPtr
End Function
' hInst : HINSTANCE optional
' name : LPCSTR
' type : GDI_IMAGE_TYPE
' cx : INT
' cy : INT
' fuLoad : IMAGE_FLAGS
Declare PtrSafe Function LoadImageA Lib "user32" ( _
    ByVal hInst As LongPtr, _
    ByVal name As String, _
    ByVal type As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal fuLoad As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadImageA = ctypes.windll.user32.LoadImageA
LoadImageA.restype = ctypes.c_void_p
LoadImageA.argtypes = [
    wintypes.HANDLE,  # hInst : HINSTANCE optional
    wintypes.LPCSTR,  # name : LPCSTR
    wintypes.DWORD,  # type : GDI_IMAGE_TYPE
    ctypes.c_int,  # cx : INT
    ctypes.c_int,  # cy : INT
    wintypes.DWORD,  # fuLoad : IMAGE_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
LoadImageA = Fiddle::Function.new(
  lib['LoadImageA'],
  [
    Fiddle::TYPE_VOIDP,  # hInst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # name : LPCSTR
    -Fiddle::TYPE_INT,  # type : GDI_IMAGE_TYPE
    Fiddle::TYPE_INT,  # cx : INT
    Fiddle::TYPE_INT,  # cy : INT
    -Fiddle::TYPE_INT,  # fuLoad : IMAGE_FLAGS
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "user32")]
extern "system" {
    fn LoadImageA(
        hInst: *mut core::ffi::c_void,  // HINSTANCE optional
        name: *const u8,  // LPCSTR
        type: u32,  // GDI_IMAGE_TYPE
        cx: i32,  // INT
        cy: i32,  // INT
        fuLoad: u32  // IMAGE_FLAGS
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr LoadImageA(IntPtr hInst, [MarshalAs(UnmanagedType.LPStr)] string name, uint type, int cx, int cy, uint fuLoad);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_LoadImageA' -Namespace Win32 -PassThru
# $api::LoadImageA(hInst, name, type, cx, cy, fuLoad)
#uselib "USER32.dll"
#func global LoadImageA "LoadImageA" sptr, sptr, sptr, sptr, sptr, sptr
; LoadImageA hInst, name, type, cx, cy, fuLoad   ; 戻り値は stat
; hInst : HINSTANCE optional -> "sptr"
; name : LPCSTR -> "sptr"
; type : GDI_IMAGE_TYPE -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; fuLoad : IMAGE_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global LoadImageA "LoadImageA" sptr, str, int, int, int, int
; res = LoadImageA(hInst, name, type, cx, cy, fuLoad)
; hInst : HINSTANCE optional -> "sptr"
; name : LPCSTR -> "str"
; type : GDI_IMAGE_TYPE -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; fuLoad : IMAGE_FLAGS -> "int"
; HANDLE LoadImageA(HINSTANCE hInst, LPCSTR name, GDI_IMAGE_TYPE type, INT cx, INT cy, IMAGE_FLAGS fuLoad)
#uselib "USER32.dll"
#cfunc global LoadImageA "LoadImageA" intptr, str, int, int, int, int
; res = LoadImageA(hInst, name, type, cx, cy, fuLoad)
; hInst : HINSTANCE optional -> "intptr"
; name : LPCSTR -> "str"
; type : GDI_IMAGE_TYPE -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; fuLoad : IMAGE_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procLoadImageA = user32.NewProc("LoadImageA")
)

// hInst (HINSTANCE optional), name (LPCSTR), type (GDI_IMAGE_TYPE), cx (INT), cy (INT), fuLoad (IMAGE_FLAGS)
r1, _, err := procLoadImageA.Call(
	uintptr(hInst),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(name))),
	uintptr(type),
	uintptr(cx),
	uintptr(cy),
	uintptr(fuLoad),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function LoadImageA(
  hInst: THandle;   // HINSTANCE optional
  name: PAnsiChar;   // LPCSTR
  type: DWORD;   // GDI_IMAGE_TYPE
  cx: Integer;   // INT
  cy: Integer;   // INT
  fuLoad: DWORD   // IMAGE_FLAGS
): THandle; stdcall;
  external 'USER32.dll' name 'LoadImageA';
result := DllCall("USER32\LoadImageA"
    , "Ptr", hInst   ; HINSTANCE optional
    , "AStr", name   ; LPCSTR
    , "UInt", type   ; GDI_IMAGE_TYPE
    , "Int", cx   ; INT
    , "Int", cy   ; INT
    , "UInt", fuLoad   ; IMAGE_FLAGS
    , "Ptr")   ; return: HANDLE
●LoadImageA(hInst, name, type, cx, cy, fuLoad) = DLL("USER32.dll", "void* LoadImageA(void*, char*, dword, int, int, dword)")
# 呼び出し: LoadImageA(hInst, name, type, cx, cy, fuLoad)
# hInst : HINSTANCE optional -> "void*"
# name : LPCSTR -> "char*"
# type : GDI_IMAGE_TYPE -> "dword"
# cx : INT -> "int"
# cy : INT -> "int"
# fuLoad : IMAGE_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。