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

ExtractAssociatedIconExA

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

シグネチャ

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

HICON ExtractAssociatedIconExA(
    HINSTANCE hInst,   // optional
    LPSTR pszIconPath,
    WORD* piIconIndex,
    WORD* piIconId
);

パラメーター

名前方向
hInstHINSTANCEoptional
pszIconPathLPSTRinout
piIconIndexWORD*inout
piIconIdWORD*inout

戻り値の型: HICON

各言語での呼び出し定義

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

HICON ExtractAssociatedIconExA(
    HINSTANCE hInst,   // optional
    LPSTR pszIconPath,
    WORD* piIconIndex,
    WORD* piIconId
);
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr ExtractAssociatedIconExA(
    IntPtr hInst,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszIconPath,   // LPSTR in/out
    ref ushort piIconIndex,   // WORD* in/out
    ref ushort piIconId   // WORD* in/out
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ExtractAssociatedIconExA(
    hInst As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPStr)> pszIconPath As System.Text.StringBuilder,   ' LPSTR in/out
    ByRef piIconIndex As UShort,   ' WORD* in/out
    ByRef piIconId As UShort   ' WORD* in/out
) As IntPtr
End Function
' hInst : HINSTANCE optional
' pszIconPath : LPSTR in/out
' piIconIndex : WORD* in/out
' piIconId : WORD* in/out
Declare PtrSafe Function ExtractAssociatedIconExA Lib "shell32" ( _
    ByVal hInst As LongPtr, _
    ByVal pszIconPath As String, _
    ByRef piIconIndex As Integer, _
    ByRef piIconId As Integer) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

lib = Fiddle.dlopen('SHELL32.dll')
ExtractAssociatedIconExA = Fiddle::Function.new(
  lib['ExtractAssociatedIconExA'],
  [
    Fiddle::TYPE_VOIDP,  # hInst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # pszIconPath : LPSTR in/out
    Fiddle::TYPE_VOIDP,  # piIconIndex : WORD* in/out
    Fiddle::TYPE_VOIDP,  # piIconId : WORD* in/out
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "shell32")]
extern "system" {
    fn ExtractAssociatedIconExA(
        hInst: *mut core::ffi::c_void,  // HINSTANCE optional
        pszIconPath: *mut u8,  // LPSTR in/out
        piIconIndex: *mut u16,  // WORD* in/out
        piIconId: *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.Ansi)]
public static extern IntPtr ExtractAssociatedIconExA(IntPtr hInst, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszIconPath, ref ushort piIconIndex, ref ushort piIconId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ExtractAssociatedIconExA' -Namespace Win32 -PassThru
# $api::ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
#uselib "SHELL32.dll"
#func global ExtractAssociatedIconExA "ExtractAssociatedIconExA" sptr, sptr, sptr, sptr
; ExtractAssociatedIconExA hInst, varptr(pszIconPath), varptr(piIconIndex), varptr(piIconId)   ; 戻り値は stat
; hInst : HINSTANCE optional -> "sptr"
; pszIconPath : LPSTR in/out -> "sptr"
; piIconIndex : WORD* in/out -> "sptr"
; piIconId : WORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global ExtractAssociatedIconExA "ExtractAssociatedIconExA" sptr, var, var, var
; res = ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
; hInst : HINSTANCE optional -> "sptr"
; pszIconPath : LPSTR in/out -> "var"
; piIconIndex : WORD* in/out -> "var"
; piIconId : WORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HICON ExtractAssociatedIconExA(HINSTANCE hInst, LPSTR pszIconPath, WORD* piIconIndex, WORD* piIconId)
#uselib "SHELL32.dll"
#cfunc global ExtractAssociatedIconExA "ExtractAssociatedIconExA" intptr, var, var, var
; res = ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
; hInst : HINSTANCE optional -> "intptr"
; pszIconPath : LPSTR in/out -> "var"
; piIconIndex : WORD* in/out -> "var"
; piIconId : WORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procExtractAssociatedIconExA = shell32.NewProc("ExtractAssociatedIconExA")
)

// hInst (HINSTANCE optional), pszIconPath (LPSTR in/out), piIconIndex (WORD* in/out), piIconId (WORD* in/out)
r1, _, err := procExtractAssociatedIconExA.Call(
	uintptr(hInst),
	uintptr(pszIconPath),
	uintptr(piIconIndex),
	uintptr(piIconId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HICON
function ExtractAssociatedIconExA(
  hInst: THandle;   // HINSTANCE optional
  pszIconPath: PAnsiChar;   // LPSTR in/out
  piIconIndex: Pointer;   // WORD* in/out
  piIconId: Pointer   // WORD* in/out
): THandle; stdcall;
  external 'SHELL32.dll' name 'ExtractAssociatedIconExA';
result := DllCall("SHELL32\ExtractAssociatedIconExA"
    , "Ptr", hInst   ; HINSTANCE optional
    , "Ptr", pszIconPath   ; LPSTR in/out
    , "Ptr", piIconIndex   ; WORD* in/out
    , "Ptr", piIconId   ; WORD* in/out
    , "Ptr")   ; return: HICON
●ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId) = DLL("SHELL32.dll", "void* ExtractAssociatedIconExA(void*, char*, void*, void*)")
# 呼び出し: ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
# hInst : HINSTANCE optional -> "void*"
# pszIconPath : LPSTR in/out -> "char*"
# piIconIndex : WORD* in/out -> "void*"
# piIconId : WORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。