Win32 API 日本語リファレンス
ホームUI.Shell › ILCreateFromPathW

ILCreateFromPathW

関数
ファイルパス(Unicode)からPIDLを生成する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll  (Unicode / -W)
#include <windows.h>

ITEMIDLIST* ILCreateFromPathW(
    LPCWSTR pszPath
);

パラメーター

名前方向
pszPathLPCWSTRin

戻り値の型: ITEMIDLIST*

各言語での呼び出し定義

// SHELL32.dll  (Unicode / -W)
#include <windows.h>

ITEMIDLIST* ILCreateFromPathW(
    LPCWSTR pszPath
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr ILCreateFromPathW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath   // LPCWSTR
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ILCreateFromPathW(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String   ' LPCWSTR
) As IntPtr
End Function
' pszPath : LPCWSTR
Declare PtrSafe Function ILCreateFromPathW Lib "shell32" ( _
    ByVal pszPath As LongPtr) 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

ILCreateFromPathW = ctypes.windll.shell32.ILCreateFromPathW
ILCreateFromPathW.restype = ctypes.c_void_p
ILCreateFromPathW.argtypes = [
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
ILCreateFromPathW = Fiddle::Function.new(
  lib['ILCreateFromPathW'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn ILCreateFromPathW(
        pszPath: *const u16  // LPCWSTR
    ) -> *mut ITEMIDLIST;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ILCreateFromPathW' -Namespace Win32 -PassThru
# $api::ILCreateFromPathW(pszPath)
#uselib "SHELL32.dll"
#func global ILCreateFromPathW "ILCreateFromPathW" wptr
; ILCreateFromPathW pszPath   ; 戻り値は stat
; pszPath : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global ILCreateFromPathW "ILCreateFromPathW" wstr
; res = ILCreateFromPathW(pszPath)
; pszPath : LPCWSTR -> "wstr"
; ITEMIDLIST* ILCreateFromPathW(LPCWSTR pszPath)
#uselib "SHELL32.dll"
#cfunc global ILCreateFromPathW "ILCreateFromPathW" wstr
; res = ILCreateFromPathW(pszPath)
; pszPath : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procILCreateFromPathW = shell32.NewProc("ILCreateFromPathW")
)

// pszPath (LPCWSTR)
r1, _, err := procILCreateFromPathW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // ITEMIDLIST*
function ILCreateFromPathW(
  pszPath: PWideChar   // LPCWSTR
): Pointer; stdcall;
  external 'SHELL32.dll' name 'ILCreateFromPathW';
result := DllCall("SHELL32\ILCreateFromPathW"
    , "WStr", pszPath   ; LPCWSTR
    , "Ptr")   ; return: ITEMIDLIST*
●ILCreateFromPathW(pszPath) = DLL("SHELL32.dll", "void* ILCreateFromPathW(char*)")
# 呼び出し: ILCreateFromPathW(pszPath)
# pszPath : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。