SHGetIconOverlayIndexA
関数シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
INT SHGetIconOverlayIndexA(
LPCSTR pszIconPath, // optional
INT iIconIndex
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszIconPath | LPCSTR | inoptional | アイコンを含むファイルの完全修飾パスを格納した、最大長 MAX_PATH の null 終端文字列へのポインターです。 |
| iIconIndex | INT | in | pszIconPath が指すファイル内でのアイコンのインデックスです。標準のオーバーレイアイコンを要求するには、pszIconPath を NULL に設定し、iIconIndex を次のいずれかに設定します。 IDO_SHGIOI_SHARE (0x0FFFFFFF)共有フォルダーを示すオーバーレイアイコンです。 IDO_SHGIOI_LINK (0x0FFFFFFE)リンクされたフォルダーまたはファイルを示すオーバーレイアイコンです。 IDO_SHGIOI_SLOWFILE (0x0FFFFFFD)低速ファイルを示すオーバーレイアイコンです。 IDO_SHGIOI_DEFAULT (0x0FFFFFFC)Windows 7 以降。項目がセット内の既定であることを示すオーバーレイアイコンです。一例として既定のプリンターがあります。 |
戻り値の型: INT
公式ドキュメント
システムイメージリスト内のオーバーレイアイコンのインデックスを返します。(ANSI)
戻り値
型: int
成功した場合はシステムイメージリスト内のオーバーレイアイコンのインデックスを返し、それ以外の場合は -1 を返します。
解説(Remarks)
アイコンオーバーレイはシステムイメージリストの一部です。アイコンオーバーレイには 2 つの識別子があります。1 つ目は、イメージリスト内の他のオーバーレイに対する相対位置を示す 1 始まりのオーバーレイインデックスです。もう 1 つは、実際のイメージを識別するイメージインデックスです。これら 2 つのインデックスは、ImageList_SetOverlayImage でプライベートイメージリストにアイコンオーバーレイを追加する際に、それぞれ iOverlay パラメーターと iImage パラメーターに割り当てる値に相当します。SHGetIconOverlayIndex はオーバーレイインデックスを返します。オーバーレイインデックスを対応するイメージインデックスに変換するには、INDEXTOOVERLAYMASK を呼び出します。
shlobj_core.h ヘッダーは、SHGetIconOverlayIndex を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll (ANSI / -A)
#include <windows.h>
INT SHGetIconOverlayIndexA(
LPCSTR pszIconPath, // optional
INT iIconIndex
);[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SHGetIconOverlayIndexA(
[MarshalAs(UnmanagedType.LPStr)] string pszIconPath, // LPCSTR optional
int iIconIndex // INT
);<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHGetIconOverlayIndexA(
<MarshalAs(UnmanagedType.LPStr)> pszIconPath As String, ' LPCSTR optional
iIconIndex As Integer ' INT
) As Integer
End Function' pszIconPath : LPCSTR optional
' iIconIndex : INT
Declare PtrSafe Function SHGetIconOverlayIndexA Lib "shell32" ( _
ByVal pszIconPath As String, _
ByVal iIconIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHGetIconOverlayIndexA = ctypes.windll.shell32.SHGetIconOverlayIndexA
SHGetIconOverlayIndexA.restype = ctypes.c_int
SHGetIconOverlayIndexA.argtypes = [
wintypes.LPCSTR, # pszIconPath : LPCSTR optional
ctypes.c_int, # iIconIndex : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHGetIconOverlayIndexA = Fiddle::Function.new(
lib['SHGetIconOverlayIndexA'],
[
Fiddle::TYPE_VOIDP, # pszIconPath : LPCSTR optional
Fiddle::TYPE_INT, # iIconIndex : INT
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHGetIconOverlayIndexA(
pszIconPath: *const u8, // LPCSTR optional
iIconIndex: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi)]
public static extern int SHGetIconOverlayIndexA([MarshalAs(UnmanagedType.LPStr)] string pszIconPath, int iIconIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHGetIconOverlayIndexA' -Namespace Win32 -PassThru
# $api::SHGetIconOverlayIndexA(pszIconPath, iIconIndex)#uselib "SHELL32.dll"
#func global SHGetIconOverlayIndexA "SHGetIconOverlayIndexA" sptr, sptr
; SHGetIconOverlayIndexA pszIconPath, iIconIndex ; 戻り値は stat
; pszIconPath : LPCSTR optional -> "sptr"
; iIconIndex : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global SHGetIconOverlayIndexA "SHGetIconOverlayIndexA" str, int
; res = SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
; pszIconPath : LPCSTR optional -> "str"
; iIconIndex : INT -> "int"; INT SHGetIconOverlayIndexA(LPCSTR pszIconPath, INT iIconIndex)
#uselib "SHELL32.dll"
#cfunc global SHGetIconOverlayIndexA "SHGetIconOverlayIndexA" str, int
; res = SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
; pszIconPath : LPCSTR optional -> "str"
; iIconIndex : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHGetIconOverlayIndexA = shell32.NewProc("SHGetIconOverlayIndexA")
)
// pszIconPath (LPCSTR optional), iIconIndex (INT)
r1, _, err := procSHGetIconOverlayIndexA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszIconPath))),
uintptr(iIconIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SHGetIconOverlayIndexA(
pszIconPath: PAnsiChar; // LPCSTR optional
iIconIndex: Integer // INT
): Integer; stdcall;
external 'SHELL32.dll' name 'SHGetIconOverlayIndexA';result := DllCall("SHELL32\SHGetIconOverlayIndexA"
, "AStr", pszIconPath ; LPCSTR optional
, "Int", iIconIndex ; INT
, "Int") ; return: INT●SHGetIconOverlayIndexA(pszIconPath, iIconIndex) = DLL("SHELL32.dll", "int SHGetIconOverlayIndexA(char*, int)")
# 呼び出し: SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
# pszIconPath : LPCSTR optional -> "char*"
# iIconIndex : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn SHGetIconOverlayIndexA(
pszIconPath: [*c]const u8, // LPCSTR optional
iIconIndex: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc SHGetIconOverlayIndexA(
pszIconPath: cstring, # LPCSTR optional
iIconIndex: int32 # INT
): int32 {.importc: "SHGetIconOverlayIndexA", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int SHGetIconOverlayIndexA(
const(char)* pszIconPath, // LPCSTR optional
int iIconIndex // INT
);ccall((:SHGetIconOverlayIndexA, "SHELL32.dll"), stdcall, Int32,
(Cstring, Int32),
pszIconPath, iIconIndex)
# pszIconPath : LPCSTR optional -> Cstring
# iIconIndex : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHGetIconOverlayIndexA(
const char* pszIconPath,
int32_t iIconIndex);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
-- pszIconPath : LPCSTR optional
-- iIconIndex : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHGetIconOverlayIndexA = lib.func('__stdcall', 'SHGetIconOverlayIndexA', 'int32_t', ['str', 'int32_t']);
// SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
// pszIconPath : LPCSTR optional -> 'str'
// iIconIndex : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHGetIconOverlayIndexA: { parameters: ["buffer", "i32"], result: "i32" },
});
// lib.symbols.SHGetIconOverlayIndexA(pszIconPath, iIconIndex)
// pszIconPath : LPCSTR optional -> "buffer"
// iIconIndex : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHGetIconOverlayIndexA(
const char* pszIconPath,
int32_t iIconIndex);
C, "SHELL32.dll");
// $ffi->SHGetIconOverlayIndexA(pszIconPath, iIconIndex);
// pszIconPath : LPCSTR optional
// iIconIndex : INT
// 構造体/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);
int SHGetIconOverlayIndexA(
String pszIconPath, // LPCSTR optional
int iIconIndex // INT
);
}@[Link("shell32")]
lib LibSHELL32
fun SHGetIconOverlayIndexA = SHGetIconOverlayIndexA(
pszIconPath : UInt8*, # LPCSTR optional
iIconIndex : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHGetIconOverlayIndexANative = Int32 Function(Pointer<Utf8>, Int32);
typedef SHGetIconOverlayIndexADart = int Function(Pointer<Utf8>, int);
final SHGetIconOverlayIndexA = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHGetIconOverlayIndexANative, SHGetIconOverlayIndexADart>('SHGetIconOverlayIndexA');
// pszIconPath : LPCSTR optional -> Pointer<Utf8>
// iIconIndex : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHGetIconOverlayIndexA(
pszIconPath: PAnsiChar; // LPCSTR optional
iIconIndex: Integer // INT
): Integer; stdcall;
external 'SHELL32.dll' name 'SHGetIconOverlayIndexA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHGetIconOverlayIndexA"
c_SHGetIconOverlayIndexA :: CString -> Int32 -> IO Int32
-- pszIconPath : LPCSTR optional -> CString
-- iIconIndex : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shgeticonoverlayindexa =
foreign "SHGetIconOverlayIndexA"
(string @-> int32_t @-> returning int32_t)
(* pszIconPath : LPCSTR optional -> string *)
(* iIconIndex : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHGetIconOverlayIndexA" shget-icon-overlay-index-a :convention :stdcall) :int32
(psz-icon-path :string) ; LPCSTR optional
(i-icon-index :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHGetIconOverlayIndexA = Win32::API::More->new('SHELL32',
'int SHGetIconOverlayIndexA(LPCSTR pszIconPath, int iIconIndex)');
# my $ret = $SHGetIconOverlayIndexA->Call($pszIconPath, $iIconIndex);
# pszIconPath : LPCSTR optional -> LPCSTR
# iIconIndex : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SHGetIconOverlayIndexW (Unicode版) — 指定アイコンのオーバーレイインデックスを取得する(Unicode版)。