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