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