SHGetSpecialFolderPathW
関数CSIDLで指定した特殊フォルダーのパス(Unicode)を取得する。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
BOOL SHGetSpecialFolderPathW(
HWND hwnd, // optional
LPWSTR pszPath,
INT csidl,
BOOL fCreate
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | optional |
| pszPath | LPWSTR | out |
| csidl | INT | in |
| fCreate | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
BOOL SHGetSpecialFolderPathW(
HWND hwnd, // optional
LPWSTR pszPath,
INT csidl,
BOOL fCreate
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool SHGetSpecialFolderPathW(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, // LPWSTR out
int csidl, // INT
bool fCreate // BOOL
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHGetSpecialFolderPathW(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder, ' LPWSTR out
csidl As Integer, ' INT
fCreate As Boolean ' BOOL
) As Boolean
End Function' hwnd : HWND optional
' pszPath : LPWSTR out
' csidl : INT
' fCreate : BOOL
Declare PtrSafe Function SHGetSpecialFolderPathW Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pszPath As LongPtr, _
ByVal csidl As Long, _
ByVal fCreate As Long) As Long
' 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
SHGetSpecialFolderPathW = ctypes.windll.shell32.SHGetSpecialFolderPathW
SHGetSpecialFolderPathW.restype = wintypes.BOOL
SHGetSpecialFolderPathW.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPWSTR, # pszPath : LPWSTR out
ctypes.c_int, # csidl : INT
wintypes.BOOL, # fCreate : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHGetSpecialFolderPathW = Fiddle::Function.new(
lib['SHGetSpecialFolderPathW'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pszPath : LPWSTR out
Fiddle::TYPE_INT, # csidl : INT
Fiddle::TYPE_INT, # fCreate : BOOL
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn SHGetSpecialFolderPathW(
hwnd: *mut core::ffi::c_void, // HWND optional
pszPath: *mut u16, // LPWSTR out
csidl: i32, // INT
fCreate: i32 // BOOL
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern bool SHGetSpecialFolderPathW(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, int csidl, bool fCreate);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHGetSpecialFolderPathW' -Namespace Win32 -PassThru
# $api::SHGetSpecialFolderPathW(hwnd, pszPath, csidl, fCreate)#uselib "SHELL32.dll"
#func global SHGetSpecialFolderPathW "SHGetSpecialFolderPathW" wptr, wptr, wptr, wptr
; SHGetSpecialFolderPathW hwnd, varptr(pszPath), csidl, fCreate ; 戻り値は stat
; hwnd : HWND optional -> "wptr"
; pszPath : LPWSTR out -> "wptr"
; csidl : INT -> "wptr"
; fCreate : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHGetSpecialFolderPathW "SHGetSpecialFolderPathW" sptr, var, int, int ; res = SHGetSpecialFolderPathW(hwnd, pszPath, csidl, fCreate) ; hwnd : HWND optional -> "sptr" ; pszPath : LPWSTR out -> "var" ; csidl : INT -> "int" ; fCreate : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHGetSpecialFolderPathW "SHGetSpecialFolderPathW" sptr, sptr, int, int ; res = SHGetSpecialFolderPathW(hwnd, varptr(pszPath), csidl, fCreate) ; hwnd : HWND optional -> "sptr" ; pszPath : LPWSTR out -> "sptr" ; csidl : INT -> "int" ; fCreate : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SHGetSpecialFolderPathW(HWND hwnd, LPWSTR pszPath, INT csidl, BOOL fCreate) #uselib "SHELL32.dll" #cfunc global SHGetSpecialFolderPathW "SHGetSpecialFolderPathW" intptr, var, int, int ; res = SHGetSpecialFolderPathW(hwnd, pszPath, csidl, fCreate) ; hwnd : HWND optional -> "intptr" ; pszPath : LPWSTR out -> "var" ; csidl : INT -> "int" ; fCreate : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SHGetSpecialFolderPathW(HWND hwnd, LPWSTR pszPath, INT csidl, BOOL fCreate) #uselib "SHELL32.dll" #cfunc global SHGetSpecialFolderPathW "SHGetSpecialFolderPathW" intptr, intptr, int, int ; res = SHGetSpecialFolderPathW(hwnd, varptr(pszPath), csidl, fCreate) ; hwnd : HWND optional -> "intptr" ; pszPath : LPWSTR out -> "intptr" ; csidl : INT -> "int" ; fCreate : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHGetSpecialFolderPathW = shell32.NewProc("SHGetSpecialFolderPathW")
)
// hwnd (HWND optional), pszPath (LPWSTR out), csidl (INT), fCreate (BOOL)
r1, _, err := procSHGetSpecialFolderPathW.Call(
uintptr(hwnd),
uintptr(pszPath),
uintptr(csidl),
uintptr(fCreate),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SHGetSpecialFolderPathW(
hwnd: THandle; // HWND optional
pszPath: PWideChar; // LPWSTR out
csidl: Integer; // INT
fCreate: BOOL // BOOL
): BOOL; stdcall;
external 'SHELL32.dll' name 'SHGetSpecialFolderPathW';result := DllCall("SHELL32\SHGetSpecialFolderPathW"
, "Ptr", hwnd ; HWND optional
, "Ptr", pszPath ; LPWSTR out
, "Int", csidl ; INT
, "Int", fCreate ; BOOL
, "Int") ; return: BOOL●SHGetSpecialFolderPathW(hwnd, pszPath, csidl, fCreate) = DLL("SHELL32.dll", "bool SHGetSpecialFolderPathW(void*, char*, int, bool)")
# 呼び出し: SHGetSpecialFolderPathW(hwnd, pszPath, csidl, fCreate)
# hwnd : HWND optional -> "void*"
# pszPath : LPWSTR out -> "char*"
# csidl : INT -> "int"
# fCreate : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。