PathIsRootW 函数 (shlwapi.h)

确定路径字符串是否引用卷的根。

语法

BOOL PathIsRootW(
  [in] LPCWSTR pszPath
);

参数

[in] pszPath

类型: LPCTSTR

指向包含要验证的路径的最大长度为 null 的字符串MAX_PATH的指针。

返回值

类型: BOOL

如果指定的路径是根路径,则返回 TRUE ;否则返回 FALSE

注解

返回“”、“X:”或“\\server\share”等路径的 TRUE。 路径,如“..\path2“或”\\server“返回 FALSE

示例

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
// String path name 1.
char buffer_1[ ] = "C:\\";
char *lpStr1;
lpStr1 = buffer_1;

// String path name 2.
char buffer_2[ ] = "path\\file";
char *lpStr2;
lpStr2 = buffer_2;

// Variable to get the return from "PathIsRoot".
int retval;

// Test case with path not absolute.
retval = PathIsRoot(lpStr1);
cout << "The return from function is       :" << retval << endl;
cout << "The path does contain a root part :" << lpStr1 << endl;

// Test case with path absolute.
retval = PathIsRoot(lpStr2);
cout << "The return from function is       :" << retval << endl;
cout << "The path does not contain part    :" << lpStr2 << endl;
}

OUTPUT:
============
The return from function is       :1
The path does contain a root part :C:\
The return from function is       :0
The path does not contain part    :path\file
============

注意

shlwapi.h 标头将 PathIsRoot 定义为别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将非特定编码别名的使用与非非特定编码的代码混合使用可能会导致不匹配,从而导致编译或运行时错误。 有关详细信息,请参阅 函数原型的约定

要求

要求
最低受支持的客户端 Windows 2000 专业版、Windows XP [仅限桌面应用]
最低受支持的服务器 Windows 2000 Server [仅限桌面应用]
目标平台 Windows
标头 shlwapi.h
Library Shlwapi.lib
DLL Shlwapi.dll (版本 4.71 或更高版本)