ExtractAssociatedIconExA
関数シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HICON ExtractAssociatedIconExA(
HINSTANCE hInst, // optional
LPSTR pszIconPath,
WORD* piIconIndex,
WORD* piIconId
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInst | HINSTANCE | optional | アイコンを抽出するモジュールのハンドルです。 |
| pszIconPath | LPSTR | inout | 呼び出し時に、アイコンを含むファイルのフルパスとファイル名を指定する文字列へのポインターです。この関数は、そのファイルから、または当該ファイルに関連付けられた実行可能ファイルからアイコンハンドルを抽出します。 この関数が戻るとき、アイコンハンドルが実行可能ファイル(このパラメーターが直接指す実行可能ファイル、または関連付けられた実行可能ファイル)から取得された場合、関数はその実行可能ファイルのフルパスとファイル名を、このパラメーターが指すバッファーに格納します。 |
| piIconIndex | WORD* | inout | 呼び出し時に、ハンドルを取得するアイコンのインデックスを指定する WORD 値へのポインターです。 この関数が戻るとき、アイコンハンドルが実行可能ファイル(lpIconPath が指す実行可能ファイル、または関連付けられた実行可能ファイル)から取得された場合、この値はそのファイル内のアイコンのインデックスを指します。 |
| piIconId | WORD* | inout | 呼び出し時に、ハンドルを取得するアイコンの ID を指定する WORD 値へのポインターです。 この関数が戻るとき、アイコンハンドルが実行可能ファイル(lpIconPath が指す実行可能ファイル、または関連付けられた実行可能ファイル)から取得された場合、この値はそのファイル内のアイコンの ID を指します。 |
戻り値の型: HICON
公式ドキュメント
ExtractAssociatedIconEx は変更される場合や利用できない場合があります。(ANSI)
戻り値
型: HICON
成功した場合はアイコンのハンドルを返します。それ以外の場合は NULL を返します。
解説(Remarks)
この関数が返すアイコンハンドルは、不要になった時点で DestroyIcon を呼び出して解放する必要があります。
shellapi.h ヘッダーは ExtractAssociatedIconEx をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング中立のエイリアスと、エンコーディング中立でないコードを混在して使用すると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconExA "ExtractAssociatedIconExA" sptr, sptr, sptr, sptr ; res = ExtractAssociatedIconExA(hInst, varptr(pszIconPath), varptr(piIconIndex), varptr(piIconId)) ; hInst : HINSTANCE optional -> "sptr" ; pszIconPath : LPSTR in/out -> "sptr" ; piIconIndex : WORD* in/out -> "sptr" ; piIconId : WORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; HICON ExtractAssociatedIconExA(HINSTANCE hInst, LPSTR pszIconPath, WORD* piIconIndex, WORD* piIconId) #uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconExA "ExtractAssociatedIconExA" intptr, intptr, intptr, intptr ; res = ExtractAssociatedIconExA(hInst, varptr(pszIconPath), varptr(piIconIndex), varptr(piIconId)) ; hInst : HINSTANCE optional -> "intptr" ; pszIconPath : LPSTR in/out -> "intptr" ; piIconIndex : WORD* in/out -> "intptr" ; piIconId : WORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HICONfunction 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)。const std = @import("std");
extern "shell32" fn ExtractAssociatedIconExA(
hInst: ?*anyopaque, // HINSTANCE optional
pszIconPath: [*c]u8, // LPSTR in/out
piIconIndex: [*c]u16, // WORD* in/out
piIconId: [*c]u16 // WORD* in/out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc ExtractAssociatedIconExA(
hInst: pointer, # HINSTANCE optional
pszIconPath: ptr char, # LPSTR in/out
piIconIndex: ptr uint16, # WORD* in/out
piIconId: ptr uint16 # WORD* in/out
): pointer {.importc: "ExtractAssociatedIconExA", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void* ExtractAssociatedIconExA(
void* hInst, // HINSTANCE optional
char* pszIconPath, // LPSTR in/out
ushort* piIconIndex, // WORD* in/out
ushort* piIconId // WORD* in/out
);ccall((:ExtractAssociatedIconExA, "SHELL32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{UInt8}, Ptr{UInt16}, Ptr{UInt16}),
hInst, pszIconPath, piIconIndex, piIconId)
# hInst : HINSTANCE optional -> Ptr{Cvoid}
# pszIconPath : LPSTR in/out -> Ptr{UInt8}
# piIconIndex : WORD* in/out -> Ptr{UInt16}
# piIconId : WORD* in/out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* ExtractAssociatedIconExA(
void* hInst,
char* pszIconPath,
uint16_t* piIconIndex,
uint16_t* piIconId);
]]
local shell32 = ffi.load("shell32")
-- shell32.ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
-- hInst : HINSTANCE optional
-- pszIconPath : LPSTR in/out
-- piIconIndex : WORD* in/out
-- piIconId : WORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const ExtractAssociatedIconExA = lib.func('__stdcall', 'ExtractAssociatedIconExA', 'void *', ['void *', 'char *', 'uint16_t *', 'uint16_t *']);
// ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
// hInst : HINSTANCE optional -> 'void *'
// pszIconPath : LPSTR in/out -> 'char *'
// piIconIndex : WORD* in/out -> 'uint16_t *'
// piIconId : WORD* in/out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
ExtractAssociatedIconExA: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId)
// hInst : HINSTANCE optional -> "pointer"
// pszIconPath : LPSTR in/out -> "buffer"
// piIconIndex : WORD* in/out -> "pointer"
// piIconId : WORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* ExtractAssociatedIconExA(
void* hInst,
char* pszIconPath,
uint16_t* piIconIndex,
uint16_t* piIconId);
C, "SHELL32.dll");
// $ffi->ExtractAssociatedIconExA(hInst, pszIconPath, piIconIndex, piIconId);
// hInst : HINSTANCE optional
// pszIconPath : LPSTR in/out
// piIconIndex : WORD* in/out
// piIconId : WORD* in/out
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class, W32APIOptions.ASCII_OPTIONS);
Pointer ExtractAssociatedIconExA(
Pointer hInst, // HINSTANCE optional
byte[] pszIconPath, // LPSTR in/out
ShortByReference piIconIndex, // WORD* in/out
ShortByReference piIconId // WORD* in/out
);
}@[Link("shell32")]
lib LibSHELL32
fun ExtractAssociatedIconExA = ExtractAssociatedIconExA(
hInst : Void*, # HINSTANCE optional
pszIconPath : UInt8*, # LPSTR in/out
piIconIndex : UInt16*, # WORD* in/out
piIconId : UInt16* # WORD* in/out
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ExtractAssociatedIconExANative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Uint16>, Pointer<Uint16>);
typedef ExtractAssociatedIconExADart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Uint16>, Pointer<Uint16>);
final ExtractAssociatedIconExA = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<ExtractAssociatedIconExANative, ExtractAssociatedIconExADart>('ExtractAssociatedIconExA');
// hInst : HINSTANCE optional -> Pointer<Void>
// pszIconPath : LPSTR in/out -> Pointer<Utf8>
// piIconIndex : WORD* in/out -> Pointer<Uint16>
// piIconId : WORD* in/out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ExtractAssociatedIconExA"
c_ExtractAssociatedIconExA :: Ptr () -> CString -> Ptr Word16 -> Ptr Word16 -> IO (Ptr ())
-- hInst : HINSTANCE optional -> Ptr ()
-- pszIconPath : LPSTR in/out -> CString
-- piIconIndex : WORD* in/out -> Ptr Word16
-- piIconId : WORD* in/out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let extractassociatediconexa =
foreign "ExtractAssociatedIconExA"
((ptr void) @-> string @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning (ptr void))
(* hInst : HINSTANCE optional -> (ptr void) *)
(* pszIconPath : LPSTR in/out -> string *)
(* piIconIndex : WORD* in/out -> (ptr uint16_t) *)
(* piIconId : WORD* in/out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("ExtractAssociatedIconExA" extract-associated-icon-ex-a :convention :stdcall) :pointer
(h-inst :pointer) ; HINSTANCE optional
(psz-icon-path :pointer) ; LPSTR in/out
(pi-icon-index :pointer) ; WORD* in/out
(pi-icon-id :pointer)) ; WORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ExtractAssociatedIconExA = Win32::API::More->new('SHELL32',
'HANDLE ExtractAssociatedIconExA(HANDLE hInst, LPSTR pszIconPath, LPVOID piIconIndex, LPVOID piIconId)');
# my $ret = $ExtractAssociatedIconExA->Call($hInst, $pszIconPath, $piIconIndex, $piIconId);
# hInst : HINSTANCE optional -> HANDLE
# pszIconPath : LPSTR in/out -> LPSTR
# piIconIndex : WORD* in/out -> LPVOID
# piIconId : WORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ExtractAssociatedIconExW (Unicode版) — ファイルに関連付けられたアイコンを索引付きで取得する。
- f ExtractAssociatedIconA — ファイルに関連付けられたアイコンのハンドルを取得する。
- f ExtractIconA — 実行ファイルから指定インデックスのアイコンを取り出す。
- f ExtractIconExA — 実行ファイルから大小のアイコンを複数取り出す。