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

SHGetSpecialFolderLocation

関数
CSIDLで指定した特殊フォルダーのPIDLを取得する。
DLLSHELL32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT SHGetSpecialFolderLocation(
    HWND hwnd,   // optional
    INT csidl,
    ITEMIDLIST** ppidl
);

パラメーター

名前方向
hwndHWNDoptional
csidlINTin
ppidlITEMIDLIST**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SHGetSpecialFolderLocation(
    HWND hwnd,   // optional
    INT csidl,
    ITEMIDLIST** ppidl
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHGetSpecialFolderLocation(
    IntPtr hwnd,   // HWND optional
    int csidl,   // INT
    IntPtr ppidl   // ITEMIDLIST** out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHGetSpecialFolderLocation(
    hwnd As IntPtr,   ' HWND optional
    csidl As Integer,   ' INT
    ppidl As IntPtr   ' ITEMIDLIST** out
) As Integer
End Function
' hwnd : HWND optional
' csidl : INT
' ppidl : ITEMIDLIST** out
Declare PtrSafe Function SHGetSpecialFolderLocation Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal csidl As Long, _
    ByVal ppidl As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHGetSpecialFolderLocation = ctypes.windll.shell32.SHGetSpecialFolderLocation
SHGetSpecialFolderLocation.restype = ctypes.c_int
SHGetSpecialFolderLocation.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND optional
    ctypes.c_int,  # csidl : INT
    ctypes.c_void_p,  # ppidl : ITEMIDLIST** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHGetSpecialFolderLocation = shell32.NewProc("SHGetSpecialFolderLocation")
)

// hwnd (HWND optional), csidl (INT), ppidl (ITEMIDLIST** out)
r1, _, err := procSHGetSpecialFolderLocation.Call(
	uintptr(hwnd),
	uintptr(csidl),
	uintptr(ppidl),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHGetSpecialFolderLocation(
  hwnd: THandle;   // HWND optional
  csidl: Integer;   // INT
  ppidl: Pointer   // ITEMIDLIST** out
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHGetSpecialFolderLocation';
result := DllCall("SHELL32\SHGetSpecialFolderLocation"
    , "Ptr", hwnd   ; HWND optional
    , "Int", csidl   ; INT
    , "Ptr", ppidl   ; ITEMIDLIST** out
    , "Int")   ; return: HRESULT
●SHGetSpecialFolderLocation(hwnd, csidl, ppidl) = DLL("SHELL32.dll", "int SHGetSpecialFolderLocation(void*, int, void*)")
# 呼び出し: SHGetSpecialFolderLocation(hwnd, csidl, ppidl)
# hwnd : HWND optional -> "void*"
# csidl : INT -> "int"
# ppidl : ITEMIDLIST** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。