PathParseIconLocationW
関数アイコン位置文字列からパスとアイコンインデックスを分離する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT PathParseIconLocationW(
LPWSTR pszIconFile
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszIconFile | LPWSTR | inout | ファイル場所文字列を含む、長さ MAX_PATH の null 終端文字列へのポインターです。"path,iconindex" の形式である必要があります。関数が返ると、pszIconFile はファイルのパスを指します。 |
戻り値の型: INT
公式ドキュメント
ファイルの場所とアイコンインデックスを含むファイル場所文字列を解析し、個別の値として返します。(Unicode)
戻り値
型: int
有効なアイコンインデックス値を返します。
解説(Remarks)
この関数は、SHGetValue によってレジストリから取得した DefaultIcon 値を受け取り、アイコンインデックスをパスから分離する際に便利です。
例
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
void main(void)
{
// Path to parse for file and icon index.
char buffer_1[ ] = "C:\\TEST\\sample.txt,3";
char *lpStr1;
lpStr1 = buffer_1;
// Return value from "PathParseIconLocation".
int retval;
// Search a path to parse for file and icon index.
retval = PathParseIconLocation(lpStr1);
cout << "The path to parse for file and icon index is : " << lpStr1 << endl;
cout << "PathParseIconLocation returns the icon index of: " << retval << endl;
}
OUTPUT:
==========
The path to parse for file and icon index is : C:\TEST\sample.txt
PathParseIconLocation returns the icon index of: 3
メモ
shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして PathParseIconLocation を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、「関数プロトタイプの規則」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT PathParseIconLocationW(
LPWSTR pszIconFile
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int PathParseIconLocationW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconFile // LPWSTR in/out
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathParseIconLocationW(
<MarshalAs(UnmanagedType.LPWStr)> pszIconFile As System.Text.StringBuilder ' LPWSTR in/out
) As Integer
End Function' pszIconFile : LPWSTR in/out
Declare PtrSafe Function PathParseIconLocationW Lib "shlwapi" ( _
ByVal pszIconFile As LongPtr) 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
PathParseIconLocationW = ctypes.windll.shlwapi.PathParseIconLocationW
PathParseIconLocationW.restype = ctypes.c_int
PathParseIconLocationW.argtypes = [
wintypes.LPWSTR, # pszIconFile : LPWSTR in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathParseIconLocationW = Fiddle::Function.new(
lib['PathParseIconLocationW'],
[
Fiddle::TYPE_VOIDP, # pszIconFile : LPWSTR in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn PathParseIconLocationW(
pszIconFile: *mut u16 // LPWSTR in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern int PathParseIconLocationW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathParseIconLocationW' -Namespace Win32 -PassThru
# $api::PathParseIconLocationW(pszIconFile)#uselib "SHLWAPI.dll"
#func global PathParseIconLocationW "PathParseIconLocationW" wptr
; PathParseIconLocationW varptr(pszIconFile) ; 戻り値は stat
; pszIconFile : LPWSTR in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global PathParseIconLocationW "PathParseIconLocationW" var ; res = PathParseIconLocationW(pszIconFile) ; pszIconFile : LPWSTR in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global PathParseIconLocationW "PathParseIconLocationW" sptr ; res = PathParseIconLocationW(varptr(pszIconFile)) ; pszIconFile : LPWSTR in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT PathParseIconLocationW(LPWSTR pszIconFile) #uselib "SHLWAPI.dll" #cfunc global PathParseIconLocationW "PathParseIconLocationW" var ; res = PathParseIconLocationW(pszIconFile) ; pszIconFile : LPWSTR in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT PathParseIconLocationW(LPWSTR pszIconFile) #uselib "SHLWAPI.dll" #cfunc global PathParseIconLocationW "PathParseIconLocationW" intptr ; res = PathParseIconLocationW(varptr(pszIconFile)) ; pszIconFile : LPWSTR in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathParseIconLocationW = shlwapi.NewProc("PathParseIconLocationW")
)
// pszIconFile (LPWSTR in/out)
r1, _, err := procPathParseIconLocationW.Call(
uintptr(pszIconFile),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction PathParseIconLocationW(
pszIconFile: PWideChar // LPWSTR in/out
): Integer; stdcall;
external 'SHLWAPI.dll' name 'PathParseIconLocationW';result := DllCall("SHLWAPI\PathParseIconLocationW"
, "Ptr", pszIconFile ; LPWSTR in/out
, "Int") ; return: INT●PathParseIconLocationW(pszIconFile) = DLL("SHLWAPI.dll", "int PathParseIconLocationW(char*)")
# 呼び出し: PathParseIconLocationW(pszIconFile)
# pszIconFile : LPWSTR in/out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "shlwapi" fn PathParseIconLocationW(
pszIconFile: [*c]u16 // LPWSTR in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc PathParseIconLocationW(
pszIconFile: ptr uint16 # LPWSTR in/out
): int32 {.importc: "PathParseIconLocationW", stdcall, dynlib: "SHLWAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "shlwapi");
extern(Windows)
int PathParseIconLocationW(
wchar* pszIconFile // LPWSTR in/out
);ccall((:PathParseIconLocationW, "SHLWAPI.dll"), stdcall, Int32,
(Ptr{UInt16},),
pszIconFile)
# pszIconFile : LPWSTR in/out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t PathParseIconLocationW(
uint16_t* pszIconFile);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.PathParseIconLocationW(pszIconFile)
-- pszIconFile : LPWSTR in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const PathParseIconLocationW = lib.func('__stdcall', 'PathParseIconLocationW', 'int32_t', ['uint16_t *']);
// PathParseIconLocationW(pszIconFile)
// pszIconFile : LPWSTR in/out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
PathParseIconLocationW: { parameters: ["buffer"], result: "i32" },
});
// lib.symbols.PathParseIconLocationW(pszIconFile)
// pszIconFile : LPWSTR in/out -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathParseIconLocationW(
uint16_t* pszIconFile);
C, "SHLWAPI.dll");
// $ffi->PathParseIconLocationW(pszIconFile);
// pszIconFile : LPWSTR 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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.UNICODE_OPTIONS);
int PathParseIconLocationW(
char[] pszIconFile // LPWSTR in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("shlwapi")]
lib LibSHLWAPI
fun PathParseIconLocationW = PathParseIconLocationW(
pszIconFile : UInt16* # LPWSTR in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathParseIconLocationWNative = Int32 Function(Pointer<Utf16>);
typedef PathParseIconLocationWDart = int Function(Pointer<Utf16>);
final PathParseIconLocationW = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<PathParseIconLocationWNative, PathParseIconLocationWDart>('PathParseIconLocationW');
// pszIconFile : LPWSTR in/out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PathParseIconLocationW(
pszIconFile: PWideChar // LPWSTR in/out
): Integer; stdcall;
external 'SHLWAPI.dll' name 'PathParseIconLocationW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathParseIconLocationW"
c_PathParseIconLocationW :: CWString -> IO Int32
-- pszIconFile : LPWSTR in/out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathparseiconlocationw =
foreign "PathParseIconLocationW"
((ptr uint16_t) @-> returning int32_t)
(* pszIconFile : LPWSTR in/out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("PathParseIconLocationW" path-parse-icon-location-w :convention :stdcall) :int32
(psz-icon-file :pointer)) ; LPWSTR in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathParseIconLocationW = Win32::API::More->new('SHLWAPI',
'int PathParseIconLocationW(LPWSTR pszIconFile)');
# my $ret = $PathParseIconLocationW->Call($pszIconFile);
# pszIconFile : LPWSTR in/out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f PathParseIconLocationA (ANSI版) — アイコン位置文字列からパスとアイコンインデックスを分離する。