Win32 API 日本語リファレンス
ホームUI.Shell › PathCchIsRoot

PathCchIsRoot

関数
パスがルートディレクトリを指すかどうかを判定する。
DLLapi-ms-win-core-path-l1-1-0.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

BOOL PathCchIsRoot(
    LPCWSTR pszPath   // optional
);

パラメーター

名前方向説明
pszPathLPCWSTRinoptionalパス文字列へのポインター。

戻り値の型: BOOL

公式ドキュメント

パス文字列がボリュームのルートを参照しているかどうかを判定します。この関数は、"\"、"\?&#0034;、"\?\UNC&#0034; のプレフィックスを持つパスを受け付ける点で PathIsRoot とは異なります。

戻り値

指定したパスがルートの場合は TRUE を、それ以外の場合は FALSE を返します。

解説(Remarks)

次の表は、さまざまなパスに対する PathCchIsRoot の戻り値を示しています。

パス PathCchIsRoot
"c:\" TRUE
"c:" FALSE
"c:\path1" FALSE
"\path1" TRUE
"path1" FALSE
"\\path1\path2" TRUE
"\\path1\path2\" FALSE
"\\path1\path2\path3" FALSE
"\\path1" TRUE
"\\path1\" FALSE
"\\" TRUE
"\\?\UNC\" TRUE
"\\?\UNC\path1\path2" TRUE
"\\?\UNC\path1\path2\" FALSE
"\\?\UNC\path1\path2\path3" FALSE
"\\?\UNC\path1" TRUE
"\\?\UNC\path1\" FALSE
"\\?\c:\" TRUE
"\\?\c:" FALSE
"\\?\c:\path1" FALSE
"\\?\Volume{guid}\" TRUE
"\\?\Volume{guid}" FALSE
"\\?\Volume{guid}\path1" FALSE
NULL FALSE
"" FALSE

この関数は、""、"X:"、"\\server\share" のようなパスに対して TRUE を返します。"..\path2" や "\\server" のようなパスは FALSE を返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

BOOL PathCchIsRoot(
    LPCWSTR pszPath   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern bool PathCchIsRoot(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath   // LPCWSTR optional
);
<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchIsRoot(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String   ' LPCWSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pszPath : LPCWSTR optional
Declare PtrSafe Function PathCchIsRoot Lib "api-ms-win-core-path-l1-1-0" ( _
    ByVal pszPath As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCchIsRoot = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchIsRoot
PathCchIsRoot.restype = wintypes.BOOL
PathCchIsRoot.argtypes = [
    wintypes.LPCWSTR,  # pszPath : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathCchIsRoot = Fiddle::Function.new(
  lib['PathCchIsRoot'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
    fn PathCchIsRoot(
        pszPath: *const u16  // LPCWSTR optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-path-l1-1-0.dll")]
public static extern bool PathCchIsRoot([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathCchIsRoot' -Namespace Win32 -PassThru
# $api::PathCchIsRoot(pszPath)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchIsRoot "PathCchIsRoot" sptr
; PathCchIsRoot pszPath   ; 戻り値は stat
; pszPath : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchIsRoot "PathCchIsRoot" wstr
; res = PathCchIsRoot(pszPath)
; pszPath : LPCWSTR optional -> "wstr"
; BOOL PathCchIsRoot(LPCWSTR pszPath)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchIsRoot "PathCchIsRoot" wstr
; res = PathCchIsRoot(pszPath)
; pszPath : LPCWSTR optional -> "wstr"
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")
	procPathCchIsRoot = api_ms_win_core_path_l1_1_0.NewProc("PathCchIsRoot")
)

// pszPath (LPCWSTR optional)
r1, _, err := procPathCchIsRoot.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function PathCchIsRoot(
  pszPath: PWideChar   // LPCWSTR optional
): BOOL; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchIsRoot';
result := DllCall("api-ms-win-core-path-l1-1-0\PathCchIsRoot"
    , "WStr", pszPath   ; LPCWSTR optional
    , "Int")   ; return: BOOL
●PathCchIsRoot(pszPath) = DLL("api-ms-win-core-path-l1-1-0.dll", "bool PathCchIsRoot(char*)")
# 呼び出し: PathCchIsRoot(pszPath)
# pszPath : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "api-ms-win-core-path-l1-1-0" fn PathCchIsRoot(
    pszPath: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) i32;
proc PathCchIsRoot(
    pszPath: WideCString  # LPCWSTR optional
): int32 {.importc: "PathCchIsRoot", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}
pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchIsRoot(
    const(wchar)* pszPath   // LPCWSTR optional
);
ccall((:PathCchIsRoot, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
      (Cwstring,),
      pszPath)
# pszPath : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PathCchIsRoot(
    const uint16_t* pszPath);
]]
local api-ms-win-core-path-l1-1-0 = ffi.load("api-ms-win-core-path-l1-1-0")
-- api-ms-win-core-path-l1-1-0.PathCchIsRoot(pszPath)
-- pszPath : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathCchIsRoot = lib.func('__stdcall', 'PathCchIsRoot', 'int32_t', ['str16']);
// PathCchIsRoot(pszPath)
// pszPath : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
  PathCchIsRoot: { parameters: ["buffer"], result: "i32" },
});
// lib.symbols.PathCchIsRoot(pszPath)
// pszPath : LPCWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PathCchIsRoot(
    const uint16_t* pszPath);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchIsRoot(pszPath);
// pszPath : LPCWSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Api-ms-win-core-path-l1-1-0 extends StdCallLibrary {
    Api-ms-win-core-path-l1-1-0 INSTANCE = Native.load("api-ms-win-core-path-l1-1-0", Api-ms-win-core-path-l1-1-0.class);
    boolean PathCchIsRoot(
        WString pszPath   // LPCWSTR optional
    );
}
@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
  fun PathCchIsRoot = PathCchIsRoot(
    pszPath : UInt16*   # LPCWSTR optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PathCchIsRootNative = Int32 Function(Pointer<Utf16>);
typedef PathCchIsRootDart = int Function(Pointer<Utf16>);
final PathCchIsRoot = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
    .lookupFunction<PathCchIsRootNative, PathCchIsRootDart>('PathCchIsRoot');
// pszPath : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PathCchIsRoot(
  pszPath: PWideChar   // LPCWSTR optional
): BOOL; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchIsRoot';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PathCchIsRoot"
  c_PathCchIsRoot :: CWString -> IO CInt
-- pszPath : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pathcchisroot =
  foreign "PathCchIsRoot"
    ((ptr uint16_t) @-> returning int32_t)
(* pszPath : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-core-path-l1-1-0 (t "api-ms-win-core-path-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-path-l1-1-0)

(cffi:defcfun ("PathCchIsRoot" path-cch-is-root :convention :stdcall) :int32
  (psz-path (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PathCchIsRoot = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
    'BOOL PathCchIsRoot(LPCWSTR pszPath)');
# my $ret = $PathCchIsRoot->Call($pszPath);
# pszPath : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。