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

LoadIconW

関数
アイコンリソースを読み込みハンドルを返す(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HICON LoadIconW(
    HINSTANCE hInstance,   // optional
    LPCWSTR lpIconName
);

パラメーター

名前方向
hInstanceHINSTANCEinoptional
lpIconNameLPCWSTRin

戻り値の型: HICON

各言語での呼び出し定義

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

HICON LoadIconW(
    HINSTANCE hInstance,   // optional
    LPCWSTR lpIconName
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr LoadIconW(
    IntPtr hInstance,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpIconName   // LPCWSTR
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadIconW(
    hInstance As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> lpIconName As String   ' LPCWSTR
) As IntPtr
End Function
' hInstance : HINSTANCE optional
' lpIconName : LPCWSTR
Declare PtrSafe Function LoadIconW Lib "user32" ( _
    ByVal hInstance As LongPtr, _
    ByVal lpIconName As LongPtr) 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

LoadIconW = ctypes.windll.user32.LoadIconW
LoadIconW.restype = ctypes.c_void_p
LoadIconW.argtypes = [
    wintypes.HANDLE,  # hInstance : HINSTANCE optional
    wintypes.LPCWSTR,  # lpIconName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
LoadIconW = Fiddle::Function.new(
  lib['LoadIconW'],
  [
    Fiddle::TYPE_VOIDP,  # hInstance : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # lpIconName : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn LoadIconW(
        hInstance: *mut core::ffi::c_void,  // HINSTANCE optional
        lpIconName: *const u16  // LPCWSTR
    ) -> *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 LoadIconW(IntPtr hInstance, [MarshalAs(UnmanagedType.LPWStr)] string lpIconName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_LoadIconW' -Namespace Win32 -PassThru
# $api::LoadIconW(hInstance, lpIconName)
#uselib "USER32.dll"
#func global LoadIconW "LoadIconW" wptr, wptr
; LoadIconW hInstance, lpIconName   ; 戻り値は stat
; hInstance : HINSTANCE optional -> "wptr"
; lpIconName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global LoadIconW "LoadIconW" sptr, wstr
; res = LoadIconW(hInstance, lpIconName)
; hInstance : HINSTANCE optional -> "sptr"
; lpIconName : LPCWSTR -> "wstr"
; HICON LoadIconW(HINSTANCE hInstance, LPCWSTR lpIconName)
#uselib "USER32.dll"
#cfunc global LoadIconW "LoadIconW" intptr, wstr
; res = LoadIconW(hInstance, lpIconName)
; hInstance : HINSTANCE optional -> "intptr"
; lpIconName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procLoadIconW = user32.NewProc("LoadIconW")
)

// hInstance (HINSTANCE optional), lpIconName (LPCWSTR)
r1, _, err := procLoadIconW.Call(
	uintptr(hInstance),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpIconName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HICON
function LoadIconW(
  hInstance: THandle;   // HINSTANCE optional
  lpIconName: PWideChar   // LPCWSTR
): THandle; stdcall;
  external 'USER32.dll' name 'LoadIconW';
result := DllCall("USER32\LoadIconW"
    , "Ptr", hInstance   ; HINSTANCE optional
    , "WStr", lpIconName   ; LPCWSTR
    , "Ptr")   ; return: HICON
●LoadIconW(hInstance, lpIconName) = DLL("USER32.dll", "void* LoadIconW(void*, char*)")
# 呼び出し: LoadIconW(hInstance, lpIconName)
# hInstance : HINSTANCE optional -> "void*"
# lpIconName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。