ExtractAssociatedIconA
関数ファイルに関連付けられたアイコンのハンドルを取得する。
シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HICON ExtractAssociatedIconA(
HINSTANCE hInst, // optional
LPSTR pszIconPath,
WORD* piIcon
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hInst | HINSTANCE | optional |
| pszIconPath | LPSTR | inout |
| piIcon | WORD* | inout |
戻り値の型: HICON
各言語での呼び出し定義
// 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)。