SHGetFolderLocation
関数CSIDLで指定したフォルダーのPIDLを取得する。
シグネチャ
// SHELL32.dll
#include <windows.h>
HRESULT SHGetFolderLocation(
HWND hwnd, // optional
INT csidl,
HANDLE hToken, // optional
DWORD dwFlags,
ITEMIDLIST** ppidl
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | optional |
| csidl | INT | in |
| hToken | HANDLE | inoptional |
| dwFlags | DWORD | in |
| ppidl | ITEMIDLIST** | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
HRESULT SHGetFolderLocation(
HWND hwnd, // optional
INT csidl,
HANDLE hToken, // optional
DWORD dwFlags,
ITEMIDLIST** ppidl
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHGetFolderLocation(
IntPtr hwnd, // HWND optional
int csidl, // INT
IntPtr hToken, // HANDLE optional
uint dwFlags, // DWORD
IntPtr ppidl // ITEMIDLIST** out
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHGetFolderLocation(
hwnd As IntPtr, ' HWND optional
csidl As Integer, ' INT
hToken As IntPtr, ' HANDLE optional
dwFlags As UInteger, ' DWORD
ppidl As IntPtr ' ITEMIDLIST** out
) As Integer
End Function' hwnd : HWND optional
' csidl : INT
' hToken : HANDLE optional
' dwFlags : DWORD
' ppidl : ITEMIDLIST** out
Declare PtrSafe Function SHGetFolderLocation Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal csidl As Long, _
ByVal hToken As LongPtr, _
ByVal dwFlags 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
SHGetFolderLocation = ctypes.windll.shell32.SHGetFolderLocation
SHGetFolderLocation.restype = ctypes.c_int
SHGetFolderLocation.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
ctypes.c_int, # csidl : INT
wintypes.HANDLE, # hToken : HANDLE optional
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_void_p, # ppidl : ITEMIDLIST** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHGetFolderLocation = Fiddle::Function.new(
lib['SHGetFolderLocation'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_INT, # csidl : INT
Fiddle::TYPE_VOIDP, # hToken : HANDLE optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # ppidl : ITEMIDLIST** out
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHGetFolderLocation(
hwnd: *mut core::ffi::c_void, // HWND optional
csidl: i32, // INT
hToken: *mut core::ffi::c_void, // HANDLE optional
dwFlags: u32, // DWORD
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 SHGetFolderLocation(IntPtr hwnd, int csidl, IntPtr hToken, uint dwFlags, IntPtr ppidl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHGetFolderLocation' -Namespace Win32 -PassThru
# $api::SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, ppidl)#uselib "SHELL32.dll"
#func global SHGetFolderLocation "SHGetFolderLocation" sptr, sptr, sptr, sptr, sptr
; SHGetFolderLocation hwnd, csidl, hToken, dwFlags, varptr(ppidl) ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; csidl : INT -> "sptr"
; hToken : HANDLE optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ppidl : ITEMIDLIST** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHGetFolderLocation "SHGetFolderLocation" sptr, int, sptr, int, var ; res = SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, ppidl) ; hwnd : HWND optional -> "sptr" ; csidl : INT -> "int" ; hToken : HANDLE optional -> "sptr" ; dwFlags : DWORD -> "int" ; ppidl : ITEMIDLIST** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHGetFolderLocation "SHGetFolderLocation" sptr, int, sptr, int, sptr ; res = SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, varptr(ppidl)) ; hwnd : HWND optional -> "sptr" ; csidl : INT -> "int" ; hToken : HANDLE optional -> "sptr" ; dwFlags : DWORD -> "int" ; ppidl : ITEMIDLIST** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SHGetFolderLocation(HWND hwnd, INT csidl, HANDLE hToken, DWORD dwFlags, ITEMIDLIST** ppidl) #uselib "SHELL32.dll" #cfunc global SHGetFolderLocation "SHGetFolderLocation" intptr, int, intptr, int, var ; res = SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, ppidl) ; hwnd : HWND optional -> "intptr" ; csidl : INT -> "int" ; hToken : HANDLE optional -> "intptr" ; dwFlags : DWORD -> "int" ; ppidl : ITEMIDLIST** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHGetFolderLocation(HWND hwnd, INT csidl, HANDLE hToken, DWORD dwFlags, ITEMIDLIST** ppidl) #uselib "SHELL32.dll" #cfunc global SHGetFolderLocation "SHGetFolderLocation" intptr, int, intptr, int, intptr ; res = SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, varptr(ppidl)) ; hwnd : HWND optional -> "intptr" ; csidl : INT -> "int" ; hToken : HANDLE optional -> "intptr" ; dwFlags : DWORD -> "int" ; ppidl : ITEMIDLIST** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHGetFolderLocation = shell32.NewProc("SHGetFolderLocation")
)
// hwnd (HWND optional), csidl (INT), hToken (HANDLE optional), dwFlags (DWORD), ppidl (ITEMIDLIST** out)
r1, _, err := procSHGetFolderLocation.Call(
uintptr(hwnd),
uintptr(csidl),
uintptr(hToken),
uintptr(dwFlags),
uintptr(ppidl),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHGetFolderLocation(
hwnd: THandle; // HWND optional
csidl: Integer; // INT
hToken: THandle; // HANDLE optional
dwFlags: DWORD; // DWORD
ppidl: Pointer // ITEMIDLIST** out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHGetFolderLocation';result := DllCall("SHELL32\SHGetFolderLocation"
, "Ptr", hwnd ; HWND optional
, "Int", csidl ; INT
, "Ptr", hToken ; HANDLE optional
, "UInt", dwFlags ; DWORD
, "Ptr", ppidl ; ITEMIDLIST** out
, "Int") ; return: HRESULT●SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, ppidl) = DLL("SHELL32.dll", "int SHGetFolderLocation(void*, int, void*, dword, void*)")
# 呼び出し: SHGetFolderLocation(hwnd, csidl, hToken, dwFlags, ppidl)
# hwnd : HWND optional -> "void*"
# csidl : INT -> "int"
# hToken : HANDLE optional -> "void*"
# dwFlags : DWORD -> "dword"
# ppidl : ITEMIDLIST** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。