Shell_GetCachedImageIndexW
関数シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
INT Shell_GetCachedImageIndexW(
LPCWSTR pszIconPath,
INT iIconIndex,
DWORD uIconFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszIconPath | LPCWSTR | in | 未定 (TBD) |
| iIconIndex | INT | in | pwszIconPath で指定されたファイル内のイメージのインデックスです。 |
| uIconFlags | DWORD | in | 使用されません。 - pwszIconPath [in]型: PCWSTR イメージファイルへのパスを格納したバッファーへのポインターです。 |
戻り値の型: INT
公式ドキュメント
Shell_GetCachedImageIndex は変更されるか利用できなくなる可能性があります。(Unicode)
戻り値
型: int
イメージのインデックスを返します。失敗した場合は –1 を返します。
解説(Remarks)
この関数の Shell_GetCachedImageIndexA 版および Shell_GetCachedImageIndexW 版は Windows Vista で追加されました。Unicode 文字列の場合は、Shell_GetCachedImageIndexW または Shell_GetCachedImageIndex のいずれかを呼び出します。ANSI 文字列の場合は、Shell_GetCachedImageIndexA を明示的に呼び出す必要があります。
Windows Server 2003 および Windows XP: Shell_GetCachedImageIndex のみがサポートされます。Shell_GetCachedImageIndex は Unicode 文字列を必要とします。
shlobj_core.h ヘッダーは Shell_GetCachedImageIndex を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、「関数プロトタイプの規則」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
INT Shell_GetCachedImageIndexW(
LPCWSTR pszIconPath,
INT iIconIndex,
DWORD uIconFlags
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int Shell_GetCachedImageIndexW(
[MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, // LPCWSTR
int iIconIndex, // INT
uint uIconFlags // DWORD
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function Shell_GetCachedImageIndexW(
<MarshalAs(UnmanagedType.LPWStr)> pszIconPath As String, ' LPCWSTR
iIconIndex As Integer, ' INT
uIconFlags As UInteger ' DWORD
) As Integer
End Function' pszIconPath : LPCWSTR
' iIconIndex : INT
' uIconFlags : DWORD
Declare PtrSafe Function Shell_GetCachedImageIndexW Lib "shell32" ( _
ByVal pszIconPath As LongPtr, _
ByVal iIconIndex As Long, _
ByVal uIconFlags As Long) As Long
' 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
Shell_GetCachedImageIndexW = ctypes.windll.shell32.Shell_GetCachedImageIndexW
Shell_GetCachedImageIndexW.restype = ctypes.c_int
Shell_GetCachedImageIndexW.argtypes = [
wintypes.LPCWSTR, # pszIconPath : LPCWSTR
ctypes.c_int, # iIconIndex : INT
wintypes.DWORD, # uIconFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
Shell_GetCachedImageIndexW = Fiddle::Function.new(
lib['Shell_GetCachedImageIndexW'],
[
Fiddle::TYPE_VOIDP, # pszIconPath : LPCWSTR
Fiddle::TYPE_INT, # iIconIndex : INT
-Fiddle::TYPE_INT, # uIconFlags : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn Shell_GetCachedImageIndexW(
pszIconPath: *const u16, // LPCWSTR
iIconIndex: i32, // INT
uIconFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int Shell_GetCachedImageIndexW([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIconIndex, uint uIconFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_Shell_GetCachedImageIndexW' -Namespace Win32 -PassThru
# $api::Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)#uselib "SHELL32.dll"
#func global Shell_GetCachedImageIndexW "Shell_GetCachedImageIndexW" wptr, wptr, wptr
; Shell_GetCachedImageIndexW pszIconPath, iIconIndex, uIconFlags ; 戻り値は stat
; pszIconPath : LPCWSTR -> "wptr"
; iIconIndex : INT -> "wptr"
; uIconFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global Shell_GetCachedImageIndexW "Shell_GetCachedImageIndexW" wstr, int, int
; res = Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
; pszIconPath : LPCWSTR -> "wstr"
; iIconIndex : INT -> "int"
; uIconFlags : DWORD -> "int"; INT Shell_GetCachedImageIndexW(LPCWSTR pszIconPath, INT iIconIndex, DWORD uIconFlags)
#uselib "SHELL32.dll"
#cfunc global Shell_GetCachedImageIndexW "Shell_GetCachedImageIndexW" wstr, int, int
; res = Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
; pszIconPath : LPCWSTR -> "wstr"
; iIconIndex : INT -> "int"
; uIconFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procShell_GetCachedImageIndexW = shell32.NewProc("Shell_GetCachedImageIndexW")
)
// pszIconPath (LPCWSTR), iIconIndex (INT), uIconFlags (DWORD)
r1, _, err := procShell_GetCachedImageIndexW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszIconPath))),
uintptr(iIconIndex),
uintptr(uIconFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction Shell_GetCachedImageIndexW(
pszIconPath: PWideChar; // LPCWSTR
iIconIndex: Integer; // INT
uIconFlags: DWORD // DWORD
): Integer; stdcall;
external 'SHELL32.dll' name 'Shell_GetCachedImageIndexW';result := DllCall("SHELL32\Shell_GetCachedImageIndexW"
, "WStr", pszIconPath ; LPCWSTR
, "Int", iIconIndex ; INT
, "UInt", uIconFlags ; DWORD
, "Int") ; return: INT●Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags) = DLL("SHELL32.dll", "int Shell_GetCachedImageIndexW(char*, int, dword)")
# 呼び出し: Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
# pszIconPath : LPCWSTR -> "char*"
# iIconIndex : INT -> "int"
# uIconFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "shell32" fn Shell_GetCachedImageIndexW(
pszIconPath: [*c]const u16, // LPCWSTR
iIconIndex: i32, // INT
uIconFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc Shell_GetCachedImageIndexW(
pszIconPath: WideCString, # LPCWSTR
iIconIndex: int32, # INT
uIconFlags: uint32 # DWORD
): int32 {.importc: "Shell_GetCachedImageIndexW", stdcall, dynlib: "SHELL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "shell32");
extern(Windows)
int Shell_GetCachedImageIndexW(
const(wchar)* pszIconPath, // LPCWSTR
int iIconIndex, // INT
uint uIconFlags // DWORD
);ccall((:Shell_GetCachedImageIndexW, "SHELL32.dll"), stdcall, Int32,
(Cwstring, Int32, UInt32),
pszIconPath, iIconIndex, uIconFlags)
# pszIconPath : LPCWSTR -> Cwstring
# iIconIndex : INT -> Int32
# uIconFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t Shell_GetCachedImageIndexW(
const uint16_t* pszIconPath,
int32_t iIconIndex,
uint32_t uIconFlags);
]]
local shell32 = ffi.load("shell32")
-- shell32.Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
-- pszIconPath : LPCWSTR
-- iIconIndex : INT
-- uIconFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const Shell_GetCachedImageIndexW = lib.func('__stdcall', 'Shell_GetCachedImageIndexW', 'int32_t', ['str16', 'int32_t', 'uint32_t']);
// Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
// pszIconPath : LPCWSTR -> 'str16'
// iIconIndex : INT -> 'int32_t'
// uIconFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
Shell_GetCachedImageIndexW: { parameters: ["buffer", "i32", "u32"], result: "i32" },
});
// lib.symbols.Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags)
// pszIconPath : LPCWSTR -> "buffer"
// iIconIndex : INT -> "i32"
// uIconFlags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t Shell_GetCachedImageIndexW(
const uint16_t* pszIconPath,
int32_t iIconIndex,
uint32_t uIconFlags);
C, "SHELL32.dll");
// $ffi->Shell_GetCachedImageIndexW(pszIconPath, iIconIndex, uIconFlags);
// pszIconPath : LPCWSTR
// iIconIndex : INT
// uIconFlags : DWORD
// 構造体/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.UNICODE_OPTIONS);
int Shell_GetCachedImageIndexW(
WString pszIconPath, // LPCWSTR
int iIconIndex, // INT
int uIconFlags // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("shell32")]
lib LibSHELL32
fun Shell_GetCachedImageIndexW = Shell_GetCachedImageIndexW(
pszIconPath : UInt16*, # LPCWSTR
iIconIndex : Int32, # INT
uIconFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef Shell_GetCachedImageIndexWNative = Int32 Function(Pointer<Utf16>, Int32, Uint32);
typedef Shell_GetCachedImageIndexWDart = int Function(Pointer<Utf16>, int, int);
final Shell_GetCachedImageIndexW = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<Shell_GetCachedImageIndexWNative, Shell_GetCachedImageIndexWDart>('Shell_GetCachedImageIndexW');
// pszIconPath : LPCWSTR -> Pointer<Utf16>
// iIconIndex : INT -> Int32
// uIconFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function Shell_GetCachedImageIndexW(
pszIconPath: PWideChar; // LPCWSTR
iIconIndex: Integer; // INT
uIconFlags: DWORD // DWORD
): Integer; stdcall;
external 'SHELL32.dll' name 'Shell_GetCachedImageIndexW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "Shell_GetCachedImageIndexW"
c_Shell_GetCachedImageIndexW :: CWString -> Int32 -> Word32 -> IO Int32
-- pszIconPath : LPCWSTR -> CWString
-- iIconIndex : INT -> Int32
-- uIconFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shell_getcachedimageindexw =
foreign "Shell_GetCachedImageIndexW"
((ptr uint16_t) @-> int32_t @-> uint32_t @-> returning int32_t)
(* pszIconPath : LPCWSTR -> (ptr uint16_t) *)
(* iIconIndex : INT -> int32_t *)
(* uIconFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("Shell_GetCachedImageIndexW" shell-get-cached-image-index-w :convention :stdcall) :int32
(psz-icon-path (:string :encoding :utf-16le)) ; LPCWSTR
(i-icon-index :int32) ; INT
(u-icon-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $Shell_GetCachedImageIndexW = Win32::API::More->new('SHELL32',
'int Shell_GetCachedImageIndexW(LPCWSTR pszIconPath, int iIconIndex, DWORD uIconFlags)');
# my $ret = $Shell_GetCachedImageIndexW->Call($pszIconPath, $iIconIndex, $uIconFlags);
# pszIconPath : LPCWSTR -> LPCWSTR
# iIconIndex : INT -> int
# uIconFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f Shell_GetCachedImageIndexA (ANSI版) — キャッシュ済みアイコン(ANSI)のイメージリスト内インデックスを取得する。