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

LoadImageW

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

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

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

パラメーター

名前方向
hInstHINSTANCEinoptional
nameLPCWSTRin
typeGDI_IMAGE_TYPEin
cxINTin
cyINTin
fuLoadIMAGE_FLAGSin

戻り値の型: HANDLE

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

HANDLE LoadImageW(
    HINSTANCE hInst,   // optional
    LPCWSTR name,
    GDI_IMAGE_TYPE type,
    INT cx,
    INT cy,
    IMAGE_FLAGS fuLoad
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr LoadImageW(
    IntPtr hInst,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] string name,   // LPCWSTR
    uint type,   // GDI_IMAGE_TYPE
    int cx,   // INT
    int cy,   // INT
    uint fuLoad   // IMAGE_FLAGS
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadImageW(
    hInst As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> name As String,   ' LPCWSTR
    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 : LPCWSTR
' type : GDI_IMAGE_TYPE
' cx : INT
' cy : INT
' fuLoad : IMAGE_FLAGS
Declare PtrSafe Function LoadImageW Lib "user32" ( _
    ByVal hInst As LongPtr, _
    ByVal name As LongPtr, _
    ByVal type As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal fuLoad As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadImageW = ctypes.windll.user32.LoadImageW
LoadImageW.restype = ctypes.c_void_p
LoadImageW.argtypes = [
    wintypes.HANDLE,  # hInst : HINSTANCE optional
    wintypes.LPCWSTR,  # name : LPCWSTR
    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')
LoadImageW = Fiddle::Function.new(
  lib['LoadImageW'],
  [
    Fiddle::TYPE_VOIDP,  # hInst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # name : LPCWSTR
    -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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn LoadImageW(
        hInst: *mut core::ffi::c_void,  // HINSTANCE optional
        name: *const u16,  // LPCWSTR
        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.Unicode, SetLastError = true)]
public static extern IntPtr LoadImageW(IntPtr hInst, [MarshalAs(UnmanagedType.LPWStr)] string name, uint type, int cx, int cy, uint fuLoad);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_LoadImageW' -Namespace Win32 -PassThru
# $api::LoadImageW(hInst, name, type, cx, cy, fuLoad)
#uselib "USER32.dll"
#func global LoadImageW "LoadImageW" wptr, wptr, wptr, wptr, wptr, wptr
; LoadImageW hInst, name, type, cx, cy, fuLoad   ; 戻り値は stat
; hInst : HINSTANCE optional -> "wptr"
; name : LPCWSTR -> "wptr"
; type : GDI_IMAGE_TYPE -> "wptr"
; cx : INT -> "wptr"
; cy : INT -> "wptr"
; fuLoad : IMAGE_FLAGS -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global LoadImageW "LoadImageW" sptr, wstr, int, int, int, int
; res = LoadImageW(hInst, name, type, cx, cy, fuLoad)
; hInst : HINSTANCE optional -> "sptr"
; name : LPCWSTR -> "wstr"
; type : GDI_IMAGE_TYPE -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; fuLoad : IMAGE_FLAGS -> "int"
; HANDLE LoadImageW(HINSTANCE hInst, LPCWSTR name, GDI_IMAGE_TYPE type, INT cx, INT cy, IMAGE_FLAGS fuLoad)
#uselib "USER32.dll"
#cfunc global LoadImageW "LoadImageW" intptr, wstr, int, int, int, int
; res = LoadImageW(hInst, name, type, cx, cy, fuLoad)
; hInst : HINSTANCE optional -> "intptr"
; name : LPCWSTR -> "wstr"
; 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")
	procLoadImageW = user32.NewProc("LoadImageW")
)

// hInst (HINSTANCE optional), name (LPCWSTR), type (GDI_IMAGE_TYPE), cx (INT), cy (INT), fuLoad (IMAGE_FLAGS)
r1, _, err := procLoadImageW.Call(
	uintptr(hInst),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(name))),
	uintptr(type),
	uintptr(cx),
	uintptr(cy),
	uintptr(fuLoad),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function LoadImageW(
  hInst: THandle;   // HINSTANCE optional
  name: PWideChar;   // LPCWSTR
  type: DWORD;   // GDI_IMAGE_TYPE
  cx: Integer;   // INT
  cy: Integer;   // INT
  fuLoad: DWORD   // IMAGE_FLAGS
): THandle; stdcall;
  external 'USER32.dll' name 'LoadImageW';
result := DllCall("USER32\LoadImageW"
    , "Ptr", hInst   ; HINSTANCE optional
    , "WStr", name   ; LPCWSTR
    , "UInt", type   ; GDI_IMAGE_TYPE
    , "Int", cx   ; INT
    , "Int", cy   ; INT
    , "UInt", fuLoad   ; IMAGE_FLAGS
    , "Ptr")   ; return: HANDLE
●LoadImageW(hInst, name, type, cx, cy, fuLoad) = DLL("USER32.dll", "void* LoadImageW(void*, char*, dword, int, int, dword)")
# 呼び出し: LoadImageW(hInst, name, type, cx, cy, fuLoad)
# hInst : HINSTANCE optional -> "void*"
# name : LPCWSTR -> "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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。