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

SHILCreateFromPath

関数
パスからPIDLと属性フラグを生成して取得する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

HRESULT SHILCreateFromPath(
    LPCWSTR pszPath,
    ITEMIDLIST** ppidl,
    DWORD* rgfInOut   // optional
);

パラメーター

名前方向説明
pszPathLPCWSTRin変換対象のパスを含む、最大長 MAX_PATH の null 終端文字列へのポインターです。
ppidlITEMIDLIST**outpszPath 内のパスを PIDL として表現したものです。
rgfInOutDWORD*inoutoptionalDWORD 値へのポインターです。入力時には、呼び出し元のアプリケーションが PIDL とともに取得したい、pszPath で指定されたフォルダーの属性を示します。出力時には、この値に要求された属性が格納されます。このパラメーターに指定可能な属性フラグの一覧については、IShellFolder::GetAttributesOf を参照してください。

戻り値の型: HRESULT

公式ドキュメント

SHILCreateFromPath は変更または利用不可になる可能性があります。

戻り値

型: HRESULT

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラー コードを返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

HRESULT SHILCreateFromPath(
    LPCWSTR pszPath,
    ITEMIDLIST** ppidl,
    DWORD* rgfInOut   // optional
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHILCreateFromPath(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath,   // LPCWSTR
    IntPtr ppidl,   // ITEMIDLIST** out
    IntPtr rgfInOut   // DWORD* optional, in/out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHILCreateFromPath(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String,   ' LPCWSTR
    ppidl As IntPtr,   ' ITEMIDLIST** out
    rgfInOut As IntPtr   ' DWORD* optional, in/out
) As Integer
End Function
' pszPath : LPCWSTR
' ppidl : ITEMIDLIST** out
' rgfInOut : DWORD* optional, in/out
Declare PtrSafe Function SHILCreateFromPath Lib "shell32" ( _
    ByVal pszPath As LongPtr, _
    ByVal ppidl As LongPtr, _
    ByVal rgfInOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHILCreateFromPath = ctypes.windll.shell32.SHILCreateFromPath
SHILCreateFromPath.restype = ctypes.c_int
SHILCreateFromPath.argtypes = [
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
    ctypes.c_void_p,  # ppidl : ITEMIDLIST** out
    ctypes.POINTER(wintypes.DWORD),  # rgfInOut : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHILCreateFromPath = Fiddle::Function.new(
  lib['SHILCreateFromPath'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # ppidl : ITEMIDLIST** out
    Fiddle::TYPE_VOIDP,  # rgfInOut : DWORD* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn SHILCreateFromPath(
        pszPath: *const u16,  // LPCWSTR
        ppidl: *mut *mut ITEMIDLIST,  // ITEMIDLIST** out
        rgfInOut: *mut u32  // DWORD* optional, in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHILCreateFromPath([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IntPtr ppidl, IntPtr rgfInOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHILCreateFromPath' -Namespace Win32 -PassThru
# $api::SHILCreateFromPath(pszPath, ppidl, rgfInOut)
#uselib "SHELL32.dll"
#func global SHILCreateFromPath "SHILCreateFromPath" sptr, sptr, sptr
; SHILCreateFromPath pszPath, varptr(ppidl), varptr(rgfInOut)   ; 戻り値は stat
; pszPath : LPCWSTR -> "sptr"
; ppidl : ITEMIDLIST** out -> "sptr"
; rgfInOut : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global SHILCreateFromPath "SHILCreateFromPath" wstr, var, var
; res = SHILCreateFromPath(pszPath, ppidl, rgfInOut)
; pszPath : LPCWSTR -> "wstr"
; ppidl : ITEMIDLIST** out -> "var"
; rgfInOut : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SHILCreateFromPath(LPCWSTR pszPath, ITEMIDLIST** ppidl, DWORD* rgfInOut)
#uselib "SHELL32.dll"
#cfunc global SHILCreateFromPath "SHILCreateFromPath" wstr, var, var
; res = SHILCreateFromPath(pszPath, ppidl, rgfInOut)
; pszPath : LPCWSTR -> "wstr"
; ppidl : ITEMIDLIST** out -> "var"
; rgfInOut : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHILCreateFromPath = shell32.NewProc("SHILCreateFromPath")
)

// pszPath (LPCWSTR), ppidl (ITEMIDLIST** out), rgfInOut (DWORD* optional, in/out)
r1, _, err := procSHILCreateFromPath.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
	uintptr(ppidl),
	uintptr(rgfInOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHILCreateFromPath(
  pszPath: PWideChar;   // LPCWSTR
  ppidl: Pointer;   // ITEMIDLIST** out
  rgfInOut: Pointer   // DWORD* optional, in/out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHILCreateFromPath';
result := DllCall("SHELL32\SHILCreateFromPath"
    , "WStr", pszPath   ; LPCWSTR
    , "Ptr", ppidl   ; ITEMIDLIST** out
    , "Ptr", rgfInOut   ; DWORD* optional, in/out
    , "Int")   ; return: HRESULT
●SHILCreateFromPath(pszPath, ppidl, rgfInOut) = DLL("SHELL32.dll", "int SHILCreateFromPath(char*, void*, void*)")
# 呼び出し: SHILCreateFromPath(pszPath, ppidl, rgfInOut)
# pszPath : LPCWSTR -> "char*"
# ppidl : ITEMIDLIST** out -> "void*"
# rgfInOut : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shell32" fn SHILCreateFromPath(
    pszPath: [*c]const u16, // LPCWSTR
    ppidl: [*c][*c]ITEMIDLIST, // ITEMIDLIST** out
    rgfInOut: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;
proc SHILCreateFromPath(
    pszPath: WideCString,  # LPCWSTR
    ppidl: ptr ITEMIDLIST,  # ITEMIDLIST** out
    rgfInOut: ptr uint32  # DWORD* optional, in/out
): int32 {.importc: "SHILCreateFromPath", stdcall, dynlib: "SHELL32.dll".}
pragma(lib, "shell32");
extern(Windows)
int SHILCreateFromPath(
    const(wchar)* pszPath,   // LPCWSTR
    ITEMIDLIST** ppidl,   // ITEMIDLIST** out
    uint* rgfInOut   // DWORD* optional, in/out
);
ccall((:SHILCreateFromPath, "SHELL32.dll"), stdcall, Int32,
      (Cwstring, Ptr{ITEMIDLIST}, Ptr{UInt32}),
      pszPath, ppidl, rgfInOut)
# pszPath : LPCWSTR -> Cwstring
# ppidl : ITEMIDLIST** out -> Ptr{ITEMIDLIST}
# rgfInOut : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SHILCreateFromPath(
    const uint16_t* pszPath,
    void* ppidl,
    uint32_t* rgfInOut);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHILCreateFromPath(pszPath, ppidl, rgfInOut)
-- pszPath : LPCWSTR
-- ppidl : ITEMIDLIST** out
-- rgfInOut : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHILCreateFromPath = lib.func('__stdcall', 'SHILCreateFromPath', 'int32_t', ['str16', 'void *', 'uint32_t *']);
// SHILCreateFromPath(pszPath, ppidl, rgfInOut)
// pszPath : LPCWSTR -> 'str16'
// ppidl : ITEMIDLIST** out -> 'void *'
// rgfInOut : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHELL32.dll", {
  SHILCreateFromPath: { parameters: ["buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SHILCreateFromPath(pszPath, ppidl, rgfInOut)
// pszPath : LPCWSTR -> "buffer"
// ppidl : ITEMIDLIST** out -> "pointer"
// rgfInOut : DWORD* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SHILCreateFromPath(
    const uint16_t* pszPath,
    void* ppidl,
    uint32_t* rgfInOut);
C, "SHELL32.dll");
// $ffi->SHILCreateFromPath(pszPath, ppidl, rgfInOut);
// pszPath : LPCWSTR
// ppidl : ITEMIDLIST** out
// rgfInOut : DWORD* optional, 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 Shell32 extends StdCallLibrary {
    Shell32 INSTANCE = Native.load("shell32", Shell32.class);
    int SHILCreateFromPath(
        WString pszPath,   // LPCWSTR
        Pointer ppidl,   // ITEMIDLIST** out
        IntByReference rgfInOut   // DWORD* optional, in/out
    );
}
@[Link("shell32")]
lib LibSHELL32
  fun SHILCreateFromPath = SHILCreateFromPath(
    pszPath : UInt16*,   # LPCWSTR
    ppidl : ITEMIDLIST**,   # ITEMIDLIST** out
    rgfInOut : UInt32*   # DWORD* optional, 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 SHILCreateFromPathNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>);
typedef SHILCreateFromPathDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Uint32>);
final SHILCreateFromPath = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<SHILCreateFromPathNative, SHILCreateFromPathDart>('SHILCreateFromPath');
// pszPath : LPCWSTR -> Pointer<Utf16>
// ppidl : ITEMIDLIST** out -> Pointer<Void>
// rgfInOut : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHILCreateFromPath(
  pszPath: PWideChar;   // LPCWSTR
  ppidl: Pointer;   // ITEMIDLIST** out
  rgfInOut: Pointer   // DWORD* optional, in/out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHILCreateFromPath';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHILCreateFromPath"
  c_SHILCreateFromPath :: CWString -> Ptr () -> Ptr Word32 -> IO Int32
-- pszPath : LPCWSTR -> CWString
-- ppidl : ITEMIDLIST** out -> Ptr ()
-- rgfInOut : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shilcreatefrompath =
  foreign "SHILCreateFromPath"
    ((ptr uint16_t) @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* pszPath : LPCWSTR -> (ptr uint16_t) *)
(* ppidl : ITEMIDLIST** out -> (ptr void) *)
(* rgfInOut : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)

(cffi:defcfun ("SHILCreateFromPath" shilcreate-from-path :convention :stdcall) :int32
  (psz-path (:string :encoding :utf-16le))   ; LPCWSTR
  (ppidl :pointer)   ; ITEMIDLIST** out
  (rgf-in-out :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SHILCreateFromPath = Win32::API::More->new('SHELL32',
    'int SHILCreateFromPath(LPCWSTR pszPath, LPVOID ppidl, LPVOID rgfInOut)');
# my $ret = $SHILCreateFromPath->Call($pszPath, $ppidl, $rgfInOut);
# pszPath : LPCWSTR -> LPCWSTR
# ppidl : ITEMIDLIST** out -> LPVOID
# rgfInOut : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型