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

SHCreateShellItemArray

関数
複数PIDLからシェルアイテム配列を作成する。
DLLSHELL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT SHCreateShellItemArray(
    ITEMIDLIST* pidlParent,   // optional
    IShellFolder* psf,   // optional
    DWORD cidl,
    ITEMIDLIST** ppidl,   // optional
    IShellItemArray** ppsiItemArray
);

パラメーター

名前方向説明
pidlParentITEMIDLIST*inoptionalppidl で指定された項目の親フォルダーの ID リストです。psf が指定されている場合、このパラメーターは NULL にできます。この pidlParent が指定されていない場合は、IPersistFolder2 を使用して psf パラメーターから計算されます。
psfIShellFolder*inoptionalppidl で指定された子項目の親となるシェルデータソースオブジェクトです。pidlParent が指定されている場合、このパラメーターは NULL にできます。
cidlDWORDinppidl で指定された配列の要素数です。
ppidlITEMIDLIST**inoptional配列の作成対象となる子項目 ID のリストです。この値は NULL にできます。
ppsiItemArrayIShellItemArray**outこの関数が返るときに、IShellItemArray インターフェイスポインターのアドレスが格納されます。

戻り値の型: HRESULT

公式ドキュメント

シェル項目配列オブジェクトを作成します。

戻り値

型: 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 SHCreateShellItemArray(
    ITEMIDLIST* pidlParent,   // optional
    IShellFolder* psf,   // optional
    DWORD cidl,
    ITEMIDLIST** ppidl,   // optional
    IShellItemArray** ppsiItemArray
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHCreateShellItemArray(
    IntPtr pidlParent,   // ITEMIDLIST* optional
    IntPtr psf,   // IShellFolder* optional
    uint cidl,   // DWORD
    IntPtr ppidl,   // ITEMIDLIST** optional
    IntPtr ppsiItemArray   // IShellItemArray** out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHCreateShellItemArray(
    pidlParent As IntPtr,   ' ITEMIDLIST* optional
    psf As IntPtr,   ' IShellFolder* optional
    cidl As UInteger,   ' DWORD
    ppidl As IntPtr,   ' ITEMIDLIST** optional
    ppsiItemArray As IntPtr   ' IShellItemArray** out
) As Integer
End Function
' pidlParent : ITEMIDLIST* optional
' psf : IShellFolder* optional
' cidl : DWORD
' ppidl : ITEMIDLIST** optional
' ppsiItemArray : IShellItemArray** out
Declare PtrSafe Function SHCreateShellItemArray Lib "shell32" ( _
    ByVal pidlParent As LongPtr, _
    ByVal psf As LongPtr, _
    ByVal cidl As Long, _
    ByVal ppidl As LongPtr, _
    ByVal ppsiItemArray As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHCreateShellItemArray = ctypes.windll.shell32.SHCreateShellItemArray
SHCreateShellItemArray.restype = ctypes.c_int
SHCreateShellItemArray.argtypes = [
    ctypes.c_void_p,  # pidlParent : ITEMIDLIST* optional
    ctypes.c_void_p,  # psf : IShellFolder* optional
    wintypes.DWORD,  # cidl : DWORD
    ctypes.c_void_p,  # ppidl : ITEMIDLIST** optional
    ctypes.c_void_p,  # ppsiItemArray : IShellItemArray** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHCreateShellItemArray = shell32.NewProc("SHCreateShellItemArray")
)

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

extern "shell32" fn SHCreateShellItemArray(
    pidlParent: [*c]ITEMIDLIST, // ITEMIDLIST* optional
    psf: ?*anyopaque, // IShellFolder* optional
    cidl: u32, // DWORD
    ppidl: [*c][*c]ITEMIDLIST, // ITEMIDLIST** optional
    ppsiItemArray: ?*anyopaque // IShellItemArray** out
) callconv(std.os.windows.WINAPI) i32;
proc SHCreateShellItemArray(
    pidlParent: ptr ITEMIDLIST,  # ITEMIDLIST* optional
    psf: pointer,  # IShellFolder* optional
    cidl: uint32,  # DWORD
    ppidl: ptr ITEMIDLIST,  # ITEMIDLIST** optional
    ppsiItemArray: pointer  # IShellItemArray** out
): int32 {.importc: "SHCreateShellItemArray", stdcall, dynlib: "SHELL32.dll".}
pragma(lib, "shell32");
extern(Windows)
int SHCreateShellItemArray(
    ITEMIDLIST* pidlParent,   // ITEMIDLIST* optional
    void* psf,   // IShellFolder* optional
    uint cidl,   // DWORD
    ITEMIDLIST** ppidl,   // ITEMIDLIST** optional
    void* ppsiItemArray   // IShellItemArray** out
);
ccall((:SHCreateShellItemArray, "SHELL32.dll"), stdcall, Int32,
      (Ptr{ITEMIDLIST}, Ptr{Cvoid}, UInt32, Ptr{ITEMIDLIST}, Ptr{Cvoid}),
      pidlParent, psf, cidl, ppidl, ppsiItemArray)
# pidlParent : ITEMIDLIST* optional -> Ptr{ITEMIDLIST}
# psf : IShellFolder* optional -> Ptr{Cvoid}
# cidl : DWORD -> UInt32
# ppidl : ITEMIDLIST** optional -> Ptr{ITEMIDLIST}
# ppsiItemArray : IShellItemArray** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SHCreateShellItemArray(
    void* pidlParent,
    void* psf,
    uint32_t cidl,
    void* ppidl,
    void* ppsiItemArray);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHCreateShellItemArray(pidlParent, psf, cidl, ppidl, ppsiItemArray)
-- pidlParent : ITEMIDLIST* optional
-- psf : IShellFolder* optional
-- cidl : DWORD
-- ppidl : ITEMIDLIST** optional
-- ppsiItemArray : IShellItemArray** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHCreateShellItemArray = lib.func('__stdcall', 'SHCreateShellItemArray', 'int32_t', ['void *', 'void *', 'uint32_t', 'void *', 'void *']);
// SHCreateShellItemArray(pidlParent, psf, cidl, ppidl, ppsiItemArray)
// pidlParent : ITEMIDLIST* optional -> 'void *'
// psf : IShellFolder* optional -> 'void *'
// cidl : DWORD -> 'uint32_t'
// ppidl : ITEMIDLIST** optional -> 'void *'
// ppsiItemArray : IShellItemArray** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHELL32.dll", {
  SHCreateShellItemArray: { parameters: ["pointer", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SHCreateShellItemArray(pidlParent, psf, cidl, ppidl, ppsiItemArray)
// pidlParent : ITEMIDLIST* optional -> "pointer"
// psf : IShellFolder* optional -> "pointer"
// cidl : DWORD -> "u32"
// ppidl : ITEMIDLIST** optional -> "pointer"
// ppsiItemArray : IShellItemArray** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SHCreateShellItemArray(
    void* pidlParent,
    void* psf,
    uint32_t cidl,
    void* ppidl,
    void* ppsiItemArray);
C, "SHELL32.dll");
// $ffi->SHCreateShellItemArray(pidlParent, psf, cidl, ppidl, ppsiItemArray);
// pidlParent : ITEMIDLIST* optional
// psf : IShellFolder* optional
// cidl : DWORD
// ppidl : ITEMIDLIST** optional
// ppsiItemArray : IShellItemArray** 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 SHCreateShellItemArray(
        Pointer pidlParent,   // ITEMIDLIST* optional
        Pointer psf,   // IShellFolder* optional
        int cidl,   // DWORD
        Pointer ppidl,   // ITEMIDLIST** optional
        Pointer ppsiItemArray   // IShellItemArray** out
    );
}
@[Link("shell32")]
lib LibSHELL32
  fun SHCreateShellItemArray = SHCreateShellItemArray(
    pidlParent : ITEMIDLIST*,   # ITEMIDLIST* optional
    psf : Void*,   # IShellFolder* optional
    cidl : UInt32,   # DWORD
    ppidl : ITEMIDLIST**,   # ITEMIDLIST** optional
    ppsiItemArray : Void*   # IShellItemArray** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SHCreateShellItemArrayNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef SHCreateShellItemArrayDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final SHCreateShellItemArray = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<SHCreateShellItemArrayNative, SHCreateShellItemArrayDart>('SHCreateShellItemArray');
// pidlParent : ITEMIDLIST* optional -> Pointer<Void>
// psf : IShellFolder* optional -> Pointer<Void>
// cidl : DWORD -> Uint32
// ppidl : ITEMIDLIST** optional -> Pointer<Void>
// ppsiItemArray : IShellItemArray** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHCreateShellItemArray(
  pidlParent: Pointer;   // ITEMIDLIST* optional
  psf: Pointer;   // IShellFolder* optional
  cidl: DWORD;   // DWORD
  ppidl: Pointer;   // ITEMIDLIST** optional
  ppsiItemArray: Pointer   // IShellItemArray** out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHCreateShellItemArray';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHCreateShellItemArray"
  c_SHCreateShellItemArray :: Ptr () -> Ptr () -> Word32 -> Ptr () -> Ptr () -> IO Int32
-- pidlParent : ITEMIDLIST* optional -> Ptr ()
-- psf : IShellFolder* optional -> Ptr ()
-- cidl : DWORD -> Word32
-- ppidl : ITEMIDLIST** optional -> Ptr ()
-- ppsiItemArray : IShellItemArray** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shcreateshellitemarray =
  foreign "SHCreateShellItemArray"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pidlParent : ITEMIDLIST* optional -> (ptr void) *)
(* psf : IShellFolder* optional -> (ptr void) *)
(* cidl : DWORD -> uint32_t *)
(* ppidl : ITEMIDLIST** optional -> (ptr void) *)
(* ppsiItemArray : IShellItemArray** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)

(cffi:defcfun ("SHCreateShellItemArray" shcreate-shell-item-array :convention :stdcall) :int32
  (pidl-parent :pointer)   ; ITEMIDLIST* optional
  (psf :pointer)   ; IShellFolder* optional
  (cidl :uint32)   ; DWORD
  (ppidl :pointer)   ; ITEMIDLIST** optional
  (ppsi-item-array :pointer))   ; IShellItemArray** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SHCreateShellItemArray = Win32::API::More->new('SHELL32',
    'int SHCreateShellItemArray(LPVOID pidlParent, LPVOID psf, DWORD cidl, LPVOID ppidl, LPVOID ppsiItemArray)');
# my $ret = $SHCreateShellItemArray->Call($pidlParent, $psf, $cidl, $ppidl, $ppsiItemArray);
# pidlParent : ITEMIDLIST* optional -> LPVOID
# psf : IShellFolder* optional -> LPVOID
# cidl : DWORD -> DWORD
# ppidl : ITEMIDLIST** optional -> LPVOID
# ppsiItemArray : IShellItemArray** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型