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

ExtractIconA

関数
実行ファイルから指定インデックスのアイコンを取り出す。
DLLSHELL32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HICON ExtractIconA(
    HINSTANCE hInst,   // optional
    LPCSTR pszExeFileName,
    DWORD nIconIndex
);

パラメーター

名前方向
hInstHINSTANCEoptional
pszExeFileNameLPCSTRin
nIconIndexDWORDin

戻り値の型: HICON

各言語での呼び出し定義

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

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

ExtractIconA = ctypes.windll.shell32.ExtractIconA
ExtractIconA.restype = ctypes.c_void_p
ExtractIconA.argtypes = [
    wintypes.HANDLE,  # hInst : HINSTANCE optional
    wintypes.LPCSTR,  # pszExeFileName : LPCSTR
    wintypes.DWORD,  # nIconIndex : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procExtractIconA = shell32.NewProc("ExtractIconA")
)

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