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最初に抽出するアイコンの 0 から始まるインデックス。たとえばこの値が 0 の場合、関数は指定したファイル内の最初のアイコンを抽出します。
cxIconINTin必要とするアイコンの水平方向のサイズ。「解説」を参照してください。
cyIconINTin必要とするアイコンの垂直方向のサイズ。「解説」を参照してください。
phiconHICON*outoptional返されるアイコンハンドルの配列へのポインター。
piconidDWORD*outoptional現在の表示デバイスに最も適したアイコンの、返されるリソース識別子へのポインター。この形式で識別子が利用できない場合、返される識別子は 0xFFFFFFFF になります。識別子をそれ以外の方法でも取得できない場合、返される識別子は 0 になります。
nIconsDWORDinファイルから抽出するアイコンの数。このパラメーターは、.exe ファイルおよび .dll ファイルから抽出する場合にのみ有効です。
flagsDWORDinこの関数を制御するフラグを指定します。これらのフラグは、LoadImage 関数で使用される LR_* フラグです。

戻り値の型: DWORD

公式ドキュメント

指定したファイルから抽出したアイコンのハンドルの配列を作成します。(Unicode)

戻り値

型: UINT

phicon パラメーターが NULL で、この関数が成功した場合、戻り値はファイル内のアイコンの数です。関数が失敗した場合、戻り値は 0 です。

phicon パラメーターが NULL 以外で、関数が成功した場合、戻り値は抽出されたアイコンの数です。それ以外の場合、ファイルが見つからなければ戻り値は 0xFFFFFFFF になります。

解説(Remarks)

この関数は、実行可能ファイル (.exe)、DLL (.dll)、アイコン (.ico)、カーソル (.cur)、アニメーションカーソル (.ani)、ビットマップ (.bmp) の各ファイルから抽出を行います。Windows 3.x の 16 ビット実行可能ファイル (.exe または .dll) からの抽出もサポートされています。

cxIcon および cyIcon パラメーターは、抽出するアイコンのサイズを指定します。パラメーターの LOWORD に 1 つ目のサイズ、HIWORD に 2 つ目のサイズを設定することで、2 つのサイズを抽出できます。たとえば、cxIcon と cyIcon の両パラメーターに MAKELONG(24, 48) を指定すると、24 と 48 の両方のサイズのアイコンが抽出されます。

PrivateExtractIcons で抽出したすべてのアイコンは、DestroyIcon 関数を呼び出して破棄する必要があります。

この関数は、Windows XP Service Pack 1 (SP1) および Windows Server 2003 まで SDK のヘッダーおよびライブラリに含まれていませんでした。この関数用のヘッダーファイルとインポートライブラリがない場合は、LoadLibrary および GetProcAddress を使用してこの関数を呼び出すことができます。

メモ

winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして PrivateExtractIcons を定義します。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーまたは実行時エラーの原因となることがあります。詳細については、「Conventions for Function Prototypes」を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 版の利用を推奨。
const std = @import("std");

extern "user32" fn PrivateExtractIconsW(
    szFileName: [*c]const u16, // LPCWSTR
    nIconIndex: i32, // INT
    cxIcon: i32, // INT
    cyIcon: i32, // INT
    phicon: ?*anyopaque, // HICON* optional, out
    piconid: [*c]u32, // DWORD* optional, out
    nIcons: u32, // DWORD
    flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc PrivateExtractIconsW(
    szFileName: WideCString,  # LPCWSTR
    nIconIndex: int32,  # INT
    cxIcon: int32,  # INT
    cyIcon: int32,  # INT
    phicon: pointer,  # HICON* optional, out
    piconid: ptr uint32,  # DWORD* optional, out
    nIcons: uint32,  # DWORD
    flags: uint32  # DWORD
): uint32 {.importc: "PrivateExtractIconsW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "user32");
extern(Windows)
uint PrivateExtractIconsW(
    const(wchar)* szFileName,   // LPCWSTR
    int nIconIndex,   // INT
    int cxIcon,   // INT
    int cyIcon,   // INT
    void* phicon,   // HICON* optional, out
    uint* piconid,   // DWORD* optional, out
    uint nIcons,   // DWORD
    uint flags   // DWORD
);
ccall((:PrivateExtractIconsW, "USER32.dll"), stdcall, UInt32,
      (Cwstring, Int32, Int32, Int32, Ptr{Cvoid}, Ptr{UInt32}, UInt32, UInt32),
      szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
# szFileName : LPCWSTR -> Cwstring
# nIconIndex : INT -> Int32
# cxIcon : INT -> Int32
# cyIcon : INT -> Int32
# phicon : HICON* optional, out -> Ptr{Cvoid}
# piconid : DWORD* optional, out -> Ptr{UInt32}
# nIcons : DWORD -> UInt32
# flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t PrivateExtractIconsW(
    const uint16_t* szFileName,
    int32_t nIconIndex,
    int32_t cxIcon,
    int32_t cyIcon,
    void* phicon,
    uint32_t* piconid,
    uint32_t nIcons,
    uint32_t flags);
]]
local user32 = ffi.load("user32")
-- user32.PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
-- szFileName : LPCWSTR
-- nIconIndex : INT
-- cxIcon : INT
-- cyIcon : INT
-- phicon : HICON* optional, out
-- piconid : DWORD* optional, out
-- nIcons : DWORD
-- flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const PrivateExtractIconsW = lib.func('__stdcall', 'PrivateExtractIconsW', 'uint32_t', ['str16', 'int32_t', 'int32_t', 'int32_t', 'void *', 'uint32_t *', 'uint32_t', 'uint32_t']);
// PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
// szFileName : LPCWSTR -> 'str16'
// nIconIndex : INT -> 'int32_t'
// cxIcon : INT -> 'int32_t'
// cyIcon : INT -> 'int32_t'
// phicon : HICON* optional, out -> 'void *'
// piconid : DWORD* optional, out -> 'uint32_t *'
// nIcons : DWORD -> 'uint32_t'
// flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  PrivateExtractIconsW: { parameters: ["buffer", "i32", "i32", "i32", "pointer", "pointer", "u32", "u32"], result: "u32" },
});
// lib.symbols.PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags)
// szFileName : LPCWSTR -> "buffer"
// nIconIndex : INT -> "i32"
// cxIcon : INT -> "i32"
// cyIcon : INT -> "i32"
// phicon : HICON* optional, out -> "pointer"
// piconid : DWORD* optional, out -> "pointer"
// nIcons : DWORD -> "u32"
// flags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t PrivateExtractIconsW(
    const uint16_t* szFileName,
    int32_t nIconIndex,
    int32_t cxIcon,
    int32_t cyIcon,
    void* phicon,
    uint32_t* piconid,
    uint32_t nIcons,
    uint32_t flags);
C, "USER32.dll");
// $ffi->PrivateExtractIconsW(szFileName, nIconIndex, cxIcon, cyIcon, phicon, piconid, nIcons, flags);
// szFileName : LPCWSTR
// nIconIndex : INT
// cxIcon : INT
// cyIcon : INT
// phicon : HICON* optional, out
// piconid : DWORD* optional, out
// nIcons : DWORD
// flags : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface User32 extends StdCallLibrary {
    User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
    int PrivateExtractIconsW(
        WString szFileName,   // LPCWSTR
        int nIconIndex,   // INT
        int cxIcon,   // INT
        int cyIcon,   // INT
        Pointer phicon,   // HICON* optional, out
        IntByReference piconid,   // DWORD* optional, out
        int nIcons,   // DWORD
        int flags   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("user32")]
lib LibUSER32
  fun PrivateExtractIconsW = PrivateExtractIconsW(
    szFileName : UInt16*,   # LPCWSTR
    nIconIndex : Int32,   # INT
    cxIcon : Int32,   # INT
    cyIcon : Int32,   # INT
    phicon : Void*,   # HICON* optional, out
    piconid : UInt32*,   # DWORD* optional, out
    nIcons : UInt32,   # DWORD
    flags : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PrivateExtractIconsWNative = Uint32 Function(Pointer<Utf16>, Int32, Int32, Int32, Pointer<Void>, Pointer<Uint32>, Uint32, Uint32);
typedef PrivateExtractIconsWDart = int Function(Pointer<Utf16>, int, int, int, Pointer<Void>, Pointer<Uint32>, int, int);
final PrivateExtractIconsW = DynamicLibrary.open('USER32.dll')
    .lookupFunction<PrivateExtractIconsWNative, PrivateExtractIconsWDart>('PrivateExtractIconsW');
// szFileName : LPCWSTR -> Pointer<Utf16>
// nIconIndex : INT -> Int32
// cxIcon : INT -> Int32
// cyIcon : INT -> Int32
// phicon : HICON* optional, out -> Pointer<Void>
// piconid : DWORD* optional, out -> Pointer<Uint32>
// nIcons : DWORD -> Uint32
// flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PrivateExtractIconsW"
  c_PrivateExtractIconsW :: CWString -> Int32 -> Int32 -> Int32 -> Ptr () -> Ptr Word32 -> Word32 -> Word32 -> IO Word32
-- szFileName : LPCWSTR -> CWString
-- nIconIndex : INT -> Int32
-- cxIcon : INT -> Int32
-- cyIcon : INT -> Int32
-- phicon : HICON* optional, out -> Ptr ()
-- piconid : DWORD* optional, out -> Ptr Word32
-- nIcons : DWORD -> Word32
-- flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let privateextracticonsw =
  foreign "PrivateExtractIconsW"
    ((ptr uint16_t) @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr uint32_t) @-> uint32_t @-> uint32_t @-> returning uint32_t)
(* szFileName : LPCWSTR -> (ptr uint16_t) *)
(* nIconIndex : INT -> int32_t *)
(* cxIcon : INT -> int32_t *)
(* cyIcon : INT -> int32_t *)
(* phicon : HICON* optional, out -> (ptr void) *)
(* piconid : DWORD* optional, out -> (ptr uint32_t) *)
(* nIcons : DWORD -> uint32_t *)
(* flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("PrivateExtractIconsW" private-extract-icons-w :convention :stdcall) :uint32
  (sz-file-name (:string :encoding :utf-16le))   ; LPCWSTR
  (n-icon-index :int32)   ; INT
  (cx-icon :int32)   ; INT
  (cy-icon :int32)   ; INT
  (phicon :pointer)   ; HICON* optional, out
  (piconid :pointer)   ; DWORD* optional, out
  (n-icons :uint32)   ; DWORD
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PrivateExtractIconsW = Win32::API::More->new('USER32',
    'DWORD PrivateExtractIconsW(LPCWSTR szFileName, int nIconIndex, int cxIcon, int cyIcon, HANDLE phicon, LPVOID piconid, DWORD nIcons, DWORD flags)');
# my $ret = $PrivateExtractIconsW->Call($szFileName, $nIconIndex, $cxIcon, $cyIcon, $phicon, $piconid, $nIcons, $flags);
# szFileName : LPCWSTR -> LPCWSTR
# nIconIndex : INT -> int
# cxIcon : INT -> int
# cyIcon : INT -> int
# phicon : HICON* optional, out -> HANDLE
# piconid : DWORD* optional, out -> LPVOID
# nIcons : DWORD -> DWORD
# flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目