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

ExtractIconExW

関数
実行ファイルから大小のアイコンを複数取り出す。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD ExtractIconExW(
    LPCWSTR lpszFile,
    INT nIconIndex,
    HICON* phiconLarge,   // optional
    HICON* phiconSmall,   // optional
    DWORD nIcons
);

パラメーター

名前方向
lpszFileLPCWSTRin
nIconIndexINTin
phiconLargeHICON*outoptional
phiconSmallHICON*outoptional
nIconsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD ExtractIconExW(
    LPCWSTR lpszFile,
    INT nIconIndex,
    HICON* phiconLarge,   // optional
    HICON* phiconSmall,   // optional
    DWORD nIcons
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint ExtractIconExW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszFile,   // LPCWSTR
    int nIconIndex,   // INT
    IntPtr phiconLarge,   // HICON* optional, out
    IntPtr phiconSmall,   // HICON* optional, out
    uint nIcons   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ExtractIconExW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszFile As String,   ' LPCWSTR
    nIconIndex As Integer,   ' INT
    phiconLarge As IntPtr,   ' HICON* optional, out
    phiconSmall As IntPtr,   ' HICON* optional, out
    nIcons As UInteger   ' DWORD
) As UInteger
End Function
' lpszFile : LPCWSTR
' nIconIndex : INT
' phiconLarge : HICON* optional, out
' phiconSmall : HICON* optional, out
' nIcons : DWORD
Declare PtrSafe Function ExtractIconExW Lib "shell32" ( _
    ByVal lpszFile As LongPtr, _
    ByVal nIconIndex As Long, _
    ByVal phiconLarge As LongPtr, _
    ByVal phiconSmall As LongPtr, _
    ByVal nIcons As Long) As Long
' 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

ExtractIconExW = ctypes.windll.shell32.ExtractIconExW
ExtractIconExW.restype = wintypes.DWORD
ExtractIconExW.argtypes = [
    wintypes.LPCWSTR,  # lpszFile : LPCWSTR
    ctypes.c_int,  # nIconIndex : INT
    ctypes.c_void_p,  # phiconLarge : HICON* optional, out
    ctypes.c_void_p,  # phiconSmall : HICON* optional, out
    wintypes.DWORD,  # nIcons : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
ExtractIconExW = Fiddle::Function.new(
  lib['ExtractIconExW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszFile : LPCWSTR
    Fiddle::TYPE_INT,  # nIconIndex : INT
    Fiddle::TYPE_VOIDP,  # phiconLarge : HICON* optional, out
    Fiddle::TYPE_VOIDP,  # phiconSmall : HICON* optional, out
    -Fiddle::TYPE_INT,  # nIcons : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn ExtractIconExW(
        lpszFile: *const u16,  // LPCWSTR
        nIconIndex: i32,  // INT
        phiconLarge: *mut *mut core::ffi::c_void,  // HICON* optional, out
        phiconSmall: *mut *mut core::ffi::c_void,  // HICON* optional, out
        nIcons: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint ExtractIconExW([MarshalAs(UnmanagedType.LPWStr)] string lpszFile, int nIconIndex, IntPtr phiconLarge, IntPtr phiconSmall, uint nIcons);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ExtractIconExW' -Namespace Win32 -PassThru
# $api::ExtractIconExW(lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons)
#uselib "SHELL32.dll"
#func global ExtractIconExW "ExtractIconExW" wptr, wptr, wptr, wptr, wptr
; ExtractIconExW lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons   ; 戻り値は stat
; lpszFile : LPCWSTR -> "wptr"
; nIconIndex : INT -> "wptr"
; phiconLarge : HICON* optional, out -> "wptr"
; phiconSmall : HICON* optional, out -> "wptr"
; nIcons : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global ExtractIconExW "ExtractIconExW" wstr, int, sptr, sptr, int
; res = ExtractIconExW(lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons)
; lpszFile : LPCWSTR -> "wstr"
; nIconIndex : INT -> "int"
; phiconLarge : HICON* optional, out -> "sptr"
; phiconSmall : HICON* optional, out -> "sptr"
; nIcons : DWORD -> "int"
; DWORD ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON* phiconLarge, HICON* phiconSmall, DWORD nIcons)
#uselib "SHELL32.dll"
#cfunc global ExtractIconExW "ExtractIconExW" wstr, int, intptr, intptr, int
; res = ExtractIconExW(lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons)
; lpszFile : LPCWSTR -> "wstr"
; nIconIndex : INT -> "int"
; phiconLarge : HICON* optional, out -> "intptr"
; phiconSmall : HICON* optional, out -> "intptr"
; nIcons : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procExtractIconExW = shell32.NewProc("ExtractIconExW")
)

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