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

ExtractAssociatedIconW

関数
ファイルに関連付けられたアイコンのハンドルを取得する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HICON ExtractAssociatedIconW(
    HINSTANCE hInst,   // optional
    LPWSTR pszIconPath,
    WORD* piIcon
);

パラメーター

名前方向
hInstHINSTANCEoptional
pszIconPathLPWSTRinout
piIconWORD*inout

戻り値の型: HICON

各言語での呼び出し定義

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

HICON ExtractAssociatedIconW(
    HINSTANCE hInst,   // optional
    LPWSTR pszIconPath,
    WORD* piIcon
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr ExtractAssociatedIconW(
    IntPtr hInst,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconPath,   // LPWSTR in/out
    ref ushort piIcon   // WORD* in/out
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ExtractAssociatedIconW(
    hInst As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> pszIconPath As System.Text.StringBuilder,   ' LPWSTR in/out
    ByRef piIcon As UShort   ' WORD* in/out
) As IntPtr
End Function
' hInst : HINSTANCE optional
' pszIconPath : LPWSTR in/out
' piIcon : WORD* in/out
Declare PtrSafe Function ExtractAssociatedIconW Lib "shell32" ( _
    ByVal hInst As LongPtr, _
    ByVal pszIconPath As LongPtr, _
    ByRef piIcon As Integer) As LongPtr
' 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

ExtractAssociatedIconW = ctypes.windll.shell32.ExtractAssociatedIconW
ExtractAssociatedIconW.restype = ctypes.c_void_p
ExtractAssociatedIconW.argtypes = [
    wintypes.HANDLE,  # hInst : HINSTANCE optional
    wintypes.LPWSTR,  # pszIconPath : LPWSTR in/out
    ctypes.POINTER(ctypes.c_ushort),  # piIcon : WORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
ExtractAssociatedIconW = Fiddle::Function.new(
  lib['ExtractAssociatedIconW'],
  [
    Fiddle::TYPE_VOIDP,  # hInst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # pszIconPath : LPWSTR in/out
    Fiddle::TYPE_VOIDP,  # piIcon : WORD* in/out
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn ExtractAssociatedIconW(
        hInst: *mut core::ffi::c_void,  // HINSTANCE optional
        pszIconPath: *mut u16,  // LPWSTR in/out
        piIcon: *mut u16  // WORD* in/out
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr ExtractAssociatedIconW(IntPtr hInst, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconPath, ref ushort piIcon);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ExtractAssociatedIconW' -Namespace Win32 -PassThru
# $api::ExtractAssociatedIconW(hInst, pszIconPath, piIcon)
#uselib "SHELL32.dll"
#func global ExtractAssociatedIconW "ExtractAssociatedIconW" wptr, wptr, wptr
; ExtractAssociatedIconW hInst, varptr(pszIconPath), varptr(piIcon)   ; 戻り値は stat
; hInst : HINSTANCE optional -> "wptr"
; pszIconPath : LPWSTR in/out -> "wptr"
; piIcon : WORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global ExtractAssociatedIconW "ExtractAssociatedIconW" sptr, var, var
; res = ExtractAssociatedIconW(hInst, pszIconPath, piIcon)
; hInst : HINSTANCE optional -> "sptr"
; pszIconPath : LPWSTR in/out -> "var"
; piIcon : WORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HICON ExtractAssociatedIconW(HINSTANCE hInst, LPWSTR pszIconPath, WORD* piIcon)
#uselib "SHELL32.dll"
#cfunc global ExtractAssociatedIconW "ExtractAssociatedIconW" intptr, var, var
; res = ExtractAssociatedIconW(hInst, pszIconPath, piIcon)
; hInst : HINSTANCE optional -> "intptr"
; pszIconPath : LPWSTR in/out -> "var"
; piIcon : WORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procExtractAssociatedIconW = shell32.NewProc("ExtractAssociatedIconW")
)

// hInst (HINSTANCE optional), pszIconPath (LPWSTR in/out), piIcon (WORD* in/out)
r1, _, err := procExtractAssociatedIconW.Call(
	uintptr(hInst),
	uintptr(pszIconPath),
	uintptr(piIcon),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HICON
function ExtractAssociatedIconW(
  hInst: THandle;   // HINSTANCE optional
  pszIconPath: PWideChar;   // LPWSTR in/out
  piIcon: Pointer   // WORD* in/out
): THandle; stdcall;
  external 'SHELL32.dll' name 'ExtractAssociatedIconW';
result := DllCall("SHELL32\ExtractAssociatedIconW"
    , "Ptr", hInst   ; HINSTANCE optional
    , "Ptr", pszIconPath   ; LPWSTR in/out
    , "Ptr", piIcon   ; WORD* in/out
    , "Ptr")   ; return: HICON
●ExtractAssociatedIconW(hInst, pszIconPath, piIcon) = DLL("SHELL32.dll", "void* ExtractAssociatedIconW(void*, char*, void*)")
# 呼び出し: ExtractAssociatedIconW(hInst, pszIconPath, piIcon)
# hInst : HINSTANCE optional -> "void*"
# pszIconPath : LPWSTR in/out -> "char*"
# piIcon : WORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。