ExtractIconW
関数実行ファイルから指定インデックスのアイコンを取り出す。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HICON ExtractIconW(
HINSTANCE hInst, // optional
LPCWSTR pszExeFileName,
DWORD nIconIndex
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hInst | HINSTANCE | optional |
| pszExeFileName | LPCWSTR | in |
| nIconIndex | DWORD | in |
戻り値の型: HICON
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
HICON ExtractIconW(
HINSTANCE hInst, // optional
LPCWSTR pszExeFileName,
DWORD nIconIndex
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr ExtractIconW(
IntPtr hInst, // HINSTANCE optional
[MarshalAs(UnmanagedType.LPWStr)] string pszExeFileName, // LPCWSTR
uint nIconIndex // DWORD
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ExtractIconW(
hInst As IntPtr, ' HINSTANCE optional
<MarshalAs(UnmanagedType.LPWStr)> pszExeFileName As String, ' LPCWSTR
nIconIndex As UInteger ' DWORD
) As IntPtr
End Function' hInst : HINSTANCE optional
' pszExeFileName : LPCWSTR
' nIconIndex : DWORD
Declare PtrSafe Function ExtractIconW Lib "shell32" ( _
ByVal hInst As LongPtr, _
ByVal pszExeFileName As LongPtr, _
ByVal nIconIndex As Long) 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
ExtractIconW = ctypes.windll.shell32.ExtractIconW
ExtractIconW.restype = ctypes.c_void_p
ExtractIconW.argtypes = [
wintypes.HANDLE, # hInst : HINSTANCE optional
wintypes.LPCWSTR, # pszExeFileName : LPCWSTR
wintypes.DWORD, # nIconIndex : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
ExtractIconW = Fiddle::Function.new(
lib['ExtractIconW'],
[
Fiddle::TYPE_VOIDP, # hInst : HINSTANCE optional
Fiddle::TYPE_VOIDP, # pszExeFileName : LPCWSTR
-Fiddle::TYPE_INT, # nIconIndex : DWORD
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn ExtractIconW(
hInst: *mut core::ffi::c_void, // HINSTANCE optional
pszExeFileName: *const u16, // LPCWSTR
nIconIndex: u32 // DWORD
) -> *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 ExtractIconW(IntPtr hInst, [MarshalAs(UnmanagedType.LPWStr)] string pszExeFileName, uint nIconIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ExtractIconW' -Namespace Win32 -PassThru
# $api::ExtractIconW(hInst, pszExeFileName, nIconIndex)#uselib "SHELL32.dll"
#func global ExtractIconW "ExtractIconW" wptr, wptr, wptr
; ExtractIconW hInst, pszExeFileName, nIconIndex ; 戻り値は stat
; hInst : HINSTANCE optional -> "wptr"
; pszExeFileName : LPCWSTR -> "wptr"
; nIconIndex : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global ExtractIconW "ExtractIconW" sptr, wstr, int
; res = ExtractIconW(hInst, pszExeFileName, nIconIndex)
; hInst : HINSTANCE optional -> "sptr"
; pszExeFileName : LPCWSTR -> "wstr"
; nIconIndex : DWORD -> "int"; HICON ExtractIconW(HINSTANCE hInst, LPCWSTR pszExeFileName, DWORD nIconIndex)
#uselib "SHELL32.dll"
#cfunc global ExtractIconW "ExtractIconW" intptr, wstr, int
; res = ExtractIconW(hInst, pszExeFileName, nIconIndex)
; hInst : HINSTANCE optional -> "intptr"
; pszExeFileName : LPCWSTR -> "wstr"
; nIconIndex : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procExtractIconW = shell32.NewProc("ExtractIconW")
)
// hInst (HINSTANCE optional), pszExeFileName (LPCWSTR), nIconIndex (DWORD)
r1, _, err := procExtractIconW.Call(
uintptr(hInst),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszExeFileName))),
uintptr(nIconIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HICONfunction ExtractIconW(
hInst: THandle; // HINSTANCE optional
pszExeFileName: PWideChar; // LPCWSTR
nIconIndex: DWORD // DWORD
): THandle; stdcall;
external 'SHELL32.dll' name 'ExtractIconW';result := DllCall("SHELL32\ExtractIconW"
, "Ptr", hInst ; HINSTANCE optional
, "WStr", pszExeFileName ; LPCWSTR
, "UInt", nIconIndex ; DWORD
, "Ptr") ; return: HICON●ExtractIconW(hInst, pszExeFileName, nIconIndex) = DLL("SHELL32.dll", "void* ExtractIconW(void*, char*, dword)")
# 呼び出し: ExtractIconW(hInst, pszExeFileName, nIconIndex)
# hInst : HINSTANCE optional -> "void*"
# pszExeFileName : LPCWSTR -> "char*"
# nIconIndex : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。