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

PrivateExtractIconsW

関数
ファイルから指定サイズのアイコンを複数抽出する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD PrivateExtractIconsW(
    LPCWSTR szFileName,
    INT nIconIndex,
    INT cxIcon,
    INT cyIcon,
    HICON* phicon,   // optional
    DWORD* piconid,   // optional
    DWORD nIcons,
    DWORD flags
);

パラメーター

名前方向
szFileNameLPCWSTRin
nIconIndexINTin
cxIconINTin
cyIconINTin
phiconHICON*outoptional
piconidDWORD*outoptional
nIconsDWORDin
flagsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD PrivateExtractIconsW(
    LPCWSTR szFileName,
    INT nIconIndex,
    INT cxIcon,
    INT cyIcon,
    HICON* phicon,   // optional
    DWORD* piconid,   // optional
    DWORD nIcons,
    DWORD flags
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint PrivateExtractIconsW(
    [MarshalAs(UnmanagedType.LPWStr)] string szFileName,   // LPCWSTR
    int nIconIndex,   // INT
    int cxIcon,   // INT
    int cyIcon,   // INT
    IntPtr phicon,   // HICON* optional, out
    IntPtr piconid,   // DWORD* optional, out
    uint nIcons,   // DWORD
    uint flags   // DWORD
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PrivateExtractIconsW(
    <MarshalAs(UnmanagedType.LPWStr)> szFileName As String,   ' LPCWSTR
    nIconIndex As Integer,   ' INT
    cxIcon As Integer,   ' INT
    cyIcon As Integer,   ' INT
    phicon As IntPtr,   ' HICON* optional, out
    piconid As IntPtr,   ' DWORD* optional, out
    nIcons As UInteger,   ' DWORD
    flags As UInteger   ' DWORD
) As UInteger
End Function
' szFileName : LPCWSTR
' nIconIndex : INT
' cxIcon : INT
' cyIcon : INT
' phicon : HICON* optional, out
' piconid : DWORD* optional, out
' nIcons : DWORD
' flags : DWORD
Declare PtrSafe Function PrivateExtractIconsW Lib "user32" ( _
    ByVal szFileName As LongPtr, _
    ByVal nIconIndex As Long, _
    ByVal cxIcon As Long, _
    ByVal cyIcon As Long, _
    ByVal phicon As LongPtr, _
    ByVal piconid As LongPtr, _
    ByVal nIcons As Long, _
    ByVal flags 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

PrivateExtractIconsW = ctypes.windll.user32.PrivateExtractIconsW
PrivateExtractIconsW.restype = wintypes.DWORD
PrivateExtractIconsW.argtypes = [
    wintypes.LPCWSTR,  # szFileName : LPCWSTR
    ctypes.c_int,  # nIconIndex : INT
    ctypes.c_int,  # cxIcon : INT
    ctypes.c_int,  # cyIcon : INT
    ctypes.c_void_p,  # phicon : HICON* optional, out
    ctypes.POINTER(wintypes.DWORD),  # piconid : DWORD* optional, out
    wintypes.DWORD,  # nIcons : DWORD
    wintypes.DWORD,  # flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
PrivateExtractIconsW = Fiddle::Function.new(
  lib['PrivateExtractIconsW'],
  [
    Fiddle::TYPE_VOIDP,  # szFileName : LPCWSTR
    Fiddle::TYPE_INT,  # nIconIndex : INT
    Fiddle::TYPE_INT,  # cxIcon : INT
    Fiddle::TYPE_INT,  # cyIcon : INT
    Fiddle::TYPE_VOIDP,  # phicon : HICON* optional, out
    Fiddle::TYPE_VOIDP,  # piconid : DWORD* optional, out
    -Fiddle::TYPE_INT,  # nIcons : DWORD
    -Fiddle::TYPE_INT,  # flags : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn PrivateExtractIconsW(
        szFileName: *const u16,  // LPCWSTR
        nIconIndex: i32,  // INT
        cxIcon: i32,  // INT
        cyIcon: i32,  // INT
        phicon: *mut *mut core::ffi::c_void,  // HICON* optional, out
        piconid: *mut u32,  // DWORD* optional, out
        nIcons: u32,  // DWORD
        flags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern uint PrivateExtractIconsW([MarshalAs(UnmanagedType.LPWStr)] string szFileName, int nIconIndex, int cxIcon, int cyIcon, IntPtr phicon, IntPtr piconid, uint nIcons, uint flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_PrivateExtractIconsW' -Namespace Win32 -PassThru
# $api::PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
#uselib "USER32.dll"
#func global PrivateExtractIconsW "PrivateExtractIconsW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; PrivateExtractIconsW szFileName, nIconIndex, cxIcon, cyIcon, phicon, varptr(piconid), nIcons, flags   ; 戻り値は stat
; szFileName : LPCWSTR -> "wptr"
; nIconIndex : INT -> "wptr"
; cxIcon : INT -> "wptr"
; cyIcon : INT -> "wptr"
; phicon : HICON* optional, out -> "wptr"
; piconid : DWORD* optional, out -> "wptr"
; nIcons : DWORD -> "wptr"
; flags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global PrivateExtractIconsW "PrivateExtractIconsW" wstr, int, int, int, sptr, var, int, int
; res = PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
; szFileName : LPCWSTR -> "wstr"
; nIconIndex : INT -> "int"
; cxIcon : INT -> "int"
; cyIcon : INT -> "int"
; phicon : HICON* optional, out -> "sptr"
; piconid : DWORD* optional, out -> "var"
; nIcons : DWORD -> "int"
; flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD PrivateExtractIconsW(LPCWSTR szFileName, INT nIconIndex, INT cxIcon, INT cyIcon, HICON* phicon, DWORD* piconid, DWORD nIcons, DWORD flags)
#uselib "USER32.dll"
#cfunc global PrivateExtractIconsW "PrivateExtractIconsW" wstr, int, int, int, intptr, var, int, int
; res = PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
; szFileName : LPCWSTR -> "wstr"
; nIconIndex : INT -> "int"
; cxIcon : INT -> "int"
; cyIcon : INT -> "int"
; phicon : HICON* optional, out -> "intptr"
; piconid : DWORD* optional, out -> "var"
; nIcons : DWORD -> "int"
; flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procPrivateExtractIconsW = user32.NewProc("PrivateExtractIconsW")
)

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