PathCchStripToRoot
関数パスをルート部分だけに切り詰める。
シグネチャ
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchStripToRoot(
LPWSTR pszPath,
UINT_PTR cchPath
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszPath | LPWSTR | inout |
| cchPath | UINT_PTR | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchStripToRoot(
LPWSTR pszPath,
UINT_PTR cchPath
);[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathCchStripToRoot(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, // LPWSTR in/out
UIntPtr cchPath // UINT_PTR
);<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchStripToRoot(
<MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder, ' LPWSTR in/out
cchPath As UIntPtr ' UINT_PTR
) As Integer
End Function' pszPath : LPWSTR in/out
' cchPath : UINT_PTR
Declare PtrSafe Function PathCchStripToRoot Lib "api-ms-win-core-path-l1-1-0" ( _
ByVal pszPath As LongPtr, _
ByVal cchPath As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathCchStripToRoot = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchStripToRoot
PathCchStripToRoot.restype = ctypes.c_int
PathCchStripToRoot.argtypes = [
wintypes.LPWSTR, # pszPath : LPWSTR in/out
ctypes.c_size_t, # cchPath : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathCchStripToRoot = Fiddle::Function.new(
lib['PathCchStripToRoot'],
[
Fiddle::TYPE_VOIDP, # pszPath : LPWSTR in/out
Fiddle::TYPE_UINTPTR_T, # cchPath : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
fn PathCchStripToRoot(
pszPath: *mut u16, // LPWSTR in/out
cchPath: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-core-path-l1-1-0.dll")]
public static extern int PathCchStripToRoot([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, UIntPtr cchPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathCchStripToRoot' -Namespace Win32 -PassThru
# $api::PathCchStripToRoot(pszPath, cchPath)#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchStripToRoot "PathCchStripToRoot" sptr, sptr
; PathCchStripToRoot varptr(pszPath), cchPath ; 戻り値は stat
; pszPath : LPWSTR in/out -> "sptr"
; cchPath : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchStripToRoot "PathCchStripToRoot" var, sptr ; res = PathCchStripToRoot(pszPath, cchPath) ; pszPath : LPWSTR in/out -> "var" ; cchPath : UINT_PTR -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchStripToRoot "PathCchStripToRoot" sptr, sptr ; res = PathCchStripToRoot(varptr(pszPath), cchPath) ; pszPath : LPWSTR in/out -> "sptr" ; cchPath : UINT_PTR -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PathCchStripToRoot(LPWSTR pszPath, UINT_PTR cchPath) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchStripToRoot "PathCchStripToRoot" var, intptr ; res = PathCchStripToRoot(pszPath, cchPath) ; pszPath : LPWSTR in/out -> "var" ; cchPath : UINT_PTR -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PathCchStripToRoot(LPWSTR pszPath, UINT_PTR cchPath) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchStripToRoot "PathCchStripToRoot" intptr, intptr ; res = PathCchStripToRoot(varptr(pszPath), cchPath) ; pszPath : LPWSTR in/out -> "intptr" ; cchPath : UINT_PTR -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_path_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-path-l1-1-0.dll")
procPathCchStripToRoot = api_ms_win_core_path_l1_1_0.NewProc("PathCchStripToRoot")
)
// pszPath (LPWSTR in/out), cchPath (UINT_PTR)
r1, _, err := procPathCchStripToRoot.Call(
uintptr(pszPath),
uintptr(cchPath),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PathCchStripToRoot(
pszPath: PWideChar; // LPWSTR in/out
cchPath: NativeUInt // UINT_PTR
): Integer; stdcall;
external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchStripToRoot';result := DllCall("api-ms-win-core-path-l1-1-0\PathCchStripToRoot"
, "Ptr", pszPath ; LPWSTR in/out
, "UPtr", cchPath ; UINT_PTR
, "Int") ; return: HRESULT●PathCchStripToRoot(pszPath, cchPath) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathCchStripToRoot(char*, int)")
# 呼び出し: PathCchStripToRoot(pszPath, cchPath)
# pszPath : LPWSTR in/out -> "char*"
# cchPath : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。