ExtractAssociatedIconA
関数シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HICON ExtractAssociatedIconA(
HINSTANCE hInst, // optional
LPSTR pszIconPath,
WORD* piIcon
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInst | HINSTANCE | optional | 呼び出し元アプリケーションのインスタンスへのハンドルです。 |
| pszIconPath | LPSTR | inout | 入力時に、アイコンを含むファイルのフルパスとファイル名を指定する文字列へのポインターです。この関数は、そのファイルから、またはそのファイルに関連付けられた実行可能ファイルからアイコンハンドルを抽出します。 この関数が戻るとき、アイコンハンドルが実行可能ファイル(lpIconPath が指す実行可能ファイル、または関連付けられた実行可能ファイル)から取得された場合、この関数はそのパラメーターが指すバッファーに、その実行可能ファイルのフルパスとファイル名を格納します。 |
| piIcon | WORD* | inout | 入力時に、ハンドルを取得するアイコンのインデックスを指定する WORD 値へのポインターです。 この関数が戻るとき、アイコンハンドルが実行可能ファイル(lpIconPath が指す実行可能ファイル、または関連付けられた実行可能ファイル)から取得された場合、この値はそのファイル内のアイコンのインデックスを指します。 |
戻り値の型: HICON
公式ドキュメント
ファイル内にリソースとして格納されているアイコン、またはファイルに関連付けられた実行可能ファイル内に格納されているアイコンへのハンドルを取得します。(ANSI)
戻り値
型: HICON
関数が成功した場合、戻り値はアイコンハンドルです。アイコンが関連付けられた実行可能ファイルから抽出された場合、この関数は lpIconPath が指す文字列にその実行可能ファイルのフルパスとファイル名を格納し、lpiIcon が指す WORD にアイコンの識別子を格納します。
関数が失敗した場合、戻り値は NULL です。
解説(Remarks)
ExtractAssociatedIcon が返すアイコンハンドルが不要になったら、呼び出し元は DestroyIcon 関数を呼び出してそのハンドルを解放する責任があります。
ExtractAssociatedIcon 関数は、まず lpIconPath で指定されたファイル内でインデックス付きアイコンを探します。そのファイルからアイコンハンドルを取得できず、かつそのファイルに関連付けられた実行可能ファイルがある場合は、その実行可能ファイル内でアイコンを探します。実行可能ファイルとの関連付けはファイル名拡張子に基づいており、レジストリのユーザーごとの部分に格納されています。
shellapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして ExtractAssociatedIcon を定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不整合が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HICON ExtractAssociatedIconA(
HINSTANCE hInst, // optional
LPSTR pszIconPath,
WORD* piIcon
);[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr ExtractAssociatedIconA(
IntPtr hInst, // HINSTANCE optional
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszIconPath, // LPSTR in/out
ref ushort piIcon // WORD* in/out
);<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ExtractAssociatedIconA(
hInst As IntPtr, ' HINSTANCE optional
<MarshalAs(UnmanagedType.LPStr)> pszIconPath As System.Text.StringBuilder, ' LPSTR in/out
ByRef piIcon As UShort ' WORD* in/out
) As IntPtr
End Function' hInst : HINSTANCE optional
' pszIconPath : LPSTR in/out
' piIcon : WORD* in/out
Declare PtrSafe Function ExtractAssociatedIconA Lib "shell32" ( _
ByVal hInst As LongPtr, _
ByVal pszIconPath As String, _
ByRef piIcon As Integer) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ExtractAssociatedIconA = ctypes.windll.shell32.ExtractAssociatedIconA
ExtractAssociatedIconA.restype = ctypes.c_void_p
ExtractAssociatedIconA.argtypes = [
wintypes.HANDLE, # hInst : HINSTANCE optional
wintypes.LPSTR, # pszIconPath : LPSTR in/out
ctypes.POINTER(ctypes.c_ushort), # piIcon : WORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
ExtractAssociatedIconA = Fiddle::Function.new(
lib['ExtractAssociatedIconA'],
[
Fiddle::TYPE_VOIDP, # hInst : HINSTANCE optional
Fiddle::TYPE_VOIDP, # pszIconPath : LPSTR in/out
Fiddle::TYPE_VOIDP, # piIcon : WORD* in/out
],
Fiddle::TYPE_VOIDP)#[link(name = "shell32")]
extern "system" {
fn ExtractAssociatedIconA(
hInst: *mut core::ffi::c_void, // HINSTANCE optional
pszIconPath: *mut u8, // LPSTR 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.Ansi)]
public static extern IntPtr ExtractAssociatedIconA(IntPtr hInst, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszIconPath, ref ushort piIcon);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ExtractAssociatedIconA' -Namespace Win32 -PassThru
# $api::ExtractAssociatedIconA(hInst, pszIconPath, piIcon)#uselib "SHELL32.dll"
#func global ExtractAssociatedIconA "ExtractAssociatedIconA" sptr, sptr, sptr
; ExtractAssociatedIconA hInst, varptr(pszIconPath), varptr(piIcon) ; 戻り値は stat
; hInst : HINSTANCE optional -> "sptr"
; pszIconPath : LPSTR in/out -> "sptr"
; piIcon : WORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconA "ExtractAssociatedIconA" sptr, var, var ; res = ExtractAssociatedIconA(hInst, pszIconPath, piIcon) ; hInst : HINSTANCE optional -> "sptr" ; pszIconPath : LPSTR in/out -> "var" ; piIcon : WORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconA "ExtractAssociatedIconA" sptr, sptr, sptr ; res = ExtractAssociatedIconA(hInst, varptr(pszIconPath), varptr(piIcon)) ; hInst : HINSTANCE optional -> "sptr" ; pszIconPath : LPSTR in/out -> "sptr" ; piIcon : WORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HICON ExtractAssociatedIconA(HINSTANCE hInst, LPSTR pszIconPath, WORD* piIcon) #uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconA "ExtractAssociatedIconA" intptr, var, var ; res = ExtractAssociatedIconA(hInst, pszIconPath, piIcon) ; hInst : HINSTANCE optional -> "intptr" ; pszIconPath : LPSTR in/out -> "var" ; piIcon : WORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HICON ExtractAssociatedIconA(HINSTANCE hInst, LPSTR pszIconPath, WORD* piIcon) #uselib "SHELL32.dll" #cfunc global ExtractAssociatedIconA "ExtractAssociatedIconA" intptr, intptr, intptr ; res = ExtractAssociatedIconA(hInst, varptr(pszIconPath), varptr(piIcon)) ; hInst : HINSTANCE optional -> "intptr" ; pszIconPath : LPSTR in/out -> "intptr" ; piIcon : WORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procExtractAssociatedIconA = shell32.NewProc("ExtractAssociatedIconA")
)
// hInst (HINSTANCE optional), pszIconPath (LPSTR in/out), piIcon (WORD* in/out)
r1, _, err := procExtractAssociatedIconA.Call(
uintptr(hInst),
uintptr(pszIconPath),
uintptr(piIcon),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HICONfunction ExtractAssociatedIconA(
hInst: THandle; // HINSTANCE optional
pszIconPath: PAnsiChar; // LPSTR in/out
piIcon: Pointer // WORD* in/out
): THandle; stdcall;
external 'SHELL32.dll' name 'ExtractAssociatedIconA';result := DllCall("SHELL32\ExtractAssociatedIconA"
, "Ptr", hInst ; HINSTANCE optional
, "Ptr", pszIconPath ; LPSTR in/out
, "Ptr", piIcon ; WORD* in/out
, "Ptr") ; return: HICON●ExtractAssociatedIconA(hInst, pszIconPath, piIcon) = DLL("SHELL32.dll", "void* ExtractAssociatedIconA(void*, char*, void*)")
# 呼び出し: ExtractAssociatedIconA(hInst, pszIconPath, piIcon)
# hInst : HINSTANCE optional -> "void*"
# pszIconPath : LPSTR in/out -> "char*"
# piIcon : WORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn ExtractAssociatedIconA(
hInst: ?*anyopaque, // HINSTANCE optional
pszIconPath: [*c]u8, // LPSTR in/out
piIcon: [*c]u16 // WORD* in/out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc ExtractAssociatedIconA(
hInst: pointer, # HINSTANCE optional
pszIconPath: ptr char, # LPSTR in/out
piIcon: ptr uint16 # WORD* in/out
): pointer {.importc: "ExtractAssociatedIconA", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void* ExtractAssociatedIconA(
void* hInst, // HINSTANCE optional
char* pszIconPath, // LPSTR in/out
ushort* piIcon // WORD* in/out
);ccall((:ExtractAssociatedIconA, "SHELL32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{UInt8}, Ptr{UInt16}),
hInst, pszIconPath, piIcon)
# hInst : HINSTANCE optional -> Ptr{Cvoid}
# pszIconPath : LPSTR in/out -> Ptr{UInt8}
# piIcon : WORD* in/out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* ExtractAssociatedIconA(
void* hInst,
char* pszIconPath,
uint16_t* piIcon);
]]
local shell32 = ffi.load("shell32")
-- shell32.ExtractAssociatedIconA(hInst, pszIconPath, piIcon)
-- hInst : HINSTANCE optional
-- pszIconPath : LPSTR in/out
-- piIcon : WORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const ExtractAssociatedIconA = lib.func('__stdcall', 'ExtractAssociatedIconA', 'void *', ['void *', 'char *', 'uint16_t *']);
// ExtractAssociatedIconA(hInst, pszIconPath, piIcon)
// hInst : HINSTANCE optional -> 'void *'
// pszIconPath : LPSTR in/out -> 'char *'
// piIcon : WORD* in/out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
ExtractAssociatedIconA: { parameters: ["pointer", "buffer", "pointer"], result: "pointer" },
});
// lib.symbols.ExtractAssociatedIconA(hInst, pszIconPath, piIcon)
// hInst : HINSTANCE optional -> "pointer"
// pszIconPath : LPSTR in/out -> "buffer"
// piIcon : WORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* ExtractAssociatedIconA(
void* hInst,
char* pszIconPath,
uint16_t* piIcon);
C, "SHELL32.dll");
// $ffi->ExtractAssociatedIconA(hInst, pszIconPath, piIcon);
// hInst : HINSTANCE optional
// pszIconPath : LPSTR in/out
// piIcon : 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 ExtractAssociatedIconA(
Pointer hInst, // HINSTANCE optional
byte[] pszIconPath, // LPSTR in/out
ShortByReference piIcon // WORD* in/out
);
}@[Link("shell32")]
lib LibSHELL32
fun ExtractAssociatedIconA = ExtractAssociatedIconA(
hInst : Void*, # HINSTANCE optional
pszIconPath : UInt8*, # LPSTR in/out
piIcon : 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 ExtractAssociatedIconANative = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Uint16>);
typedef ExtractAssociatedIconADart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Pointer<Uint16>);
final ExtractAssociatedIconA = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<ExtractAssociatedIconANative, ExtractAssociatedIconADart>('ExtractAssociatedIconA');
// hInst : HINSTANCE optional -> Pointer<Void>
// pszIconPath : LPSTR in/out -> Pointer<Utf8>
// piIcon : WORD* in/out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ExtractAssociatedIconA(
hInst: THandle; // HINSTANCE optional
pszIconPath: PAnsiChar; // LPSTR in/out
piIcon: Pointer // WORD* in/out
): THandle; stdcall;
external 'SHELL32.dll' name 'ExtractAssociatedIconA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ExtractAssociatedIconA"
c_ExtractAssociatedIconA :: Ptr () -> CString -> Ptr Word16 -> IO (Ptr ())
-- hInst : HINSTANCE optional -> Ptr ()
-- pszIconPath : LPSTR in/out -> CString
-- piIcon : WORD* in/out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let extractassociatedicona =
foreign "ExtractAssociatedIconA"
((ptr void) @-> string @-> (ptr uint16_t) @-> returning (ptr void))
(* hInst : HINSTANCE optional -> (ptr void) *)
(* pszIconPath : LPSTR in/out -> string *)
(* piIcon : 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 ("ExtractAssociatedIconA" extract-associated-icon-a :convention :stdcall) :pointer
(h-inst :pointer) ; HINSTANCE optional
(psz-icon-path :pointer) ; LPSTR in/out
(pi-icon :pointer)) ; WORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ExtractAssociatedIconA = Win32::API::More->new('SHELL32',
'HANDLE ExtractAssociatedIconA(HANDLE hInst, LPSTR pszIconPath, LPVOID piIcon)');
# my $ret = $ExtractAssociatedIconA->Call($hInst, $pszIconPath, $piIcon);
# hInst : HINSTANCE optional -> HANDLE
# pszIconPath : LPSTR in/out -> LPSTR
# piIcon : WORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ExtractAssociatedIconW (Unicode版) — ファイルに関連付けられたアイコンのハンドルを取得する。
- f ExtractAssociatedIconExA — ファイルに関連付けられたアイコンを索引付きで取得する。
- f ExtractIconA — 実行ファイルから指定インデックスのアイコンを取り出す。
- f ExtractIconExA — 実行ファイルから大小のアイコンを複数取り出す。