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

LoadIconA

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

シグネチャ

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

HICON LoadIconA(
    HINSTANCE hInstance,   // optional
    LPCSTR lpIconName
);

パラメーター

名前方向
hInstanceHINSTANCEinoptional
lpIconNameLPCSTRin

戻り値の型: HICON

各言語での呼び出し定義

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

HICON LoadIconA(
    HINSTANCE hInstance,   // optional
    LPCSTR lpIconName
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr LoadIconA(
    IntPtr hInstance,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPStr)] string lpIconName   // LPCSTR
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function LoadIconA(
    hInstance As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPStr)> lpIconName As String   ' LPCSTR
) As IntPtr
End Function
' hInstance : HINSTANCE optional
' lpIconName : LPCSTR
Declare PtrSafe Function LoadIconA Lib "user32" ( _
    ByVal hInstance As LongPtr, _
    ByVal lpIconName As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procLoadIconA = user32.NewProc("LoadIconA")
)

// hInstance (HINSTANCE optional), lpIconName (LPCSTR)
r1, _, err := procLoadIconA.Call(
	uintptr(hInstance),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpIconName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HICON
function LoadIconA(
  hInstance: THandle;   // HINSTANCE optional
  lpIconName: PAnsiChar   // LPCSTR
): THandle; stdcall;
  external 'USER32.dll' name 'LoadIconA';
result := DllCall("USER32\LoadIconA"
    , "Ptr", hInstance   ; HINSTANCE optional
    , "AStr", lpIconName   ; LPCSTR
    , "Ptr")   ; return: HICON
●LoadIconA(hInstance, lpIconName) = DLL("USER32.dll", "void* LoadIconA(void*, char*)")
# 呼び出し: LoadIconA(hInstance, lpIconName)
# hInstance : HINSTANCE optional -> "void*"
# lpIconName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。