PathGetArgsW 函数 (shlwapi.h)
查找给定路径中的命令行参数。
语法
LPCWSTR PathGetArgsW(
[in] LPCWSTR pszPath
);
参数
[in] pszPath
类型:PTSTR
指向长度为 null 的字符串的指针,该字符串的最大长度MAX_PATH,其中包含要搜索的路径。
返回值
类型:PTSTR
返回指向以 null 结尾的字符串的指针,该字符串包含路径的参数部分(如果成功)。
如果路径中没有参数,该函数将返回指向输入字符串末尾的指针。
如果为函数提供一个 NULL 参数,则返回 NULL 。
言论
不应在通用命令路径模板(用户或注册表)上使用此函数,而应仅在应用程序知道格式良好的模板上使用。
例子
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
void main( void )
{
// Path_1 to search for file arguments (2 arguments):
char buffer_1[ ] = "test.exe temp.txt sample.doc";
char *lpStr1;
lpStr1 = buffer_1;
// Path_2 to search for file arguments (3 arguments):
char buffer_2[ ] = "test.exe 1 2 3";
char *lpStr2;
lpStr2 = buffer_2;
// Path_3 to search for file arguments (3 arguments):
char buffer_3[ ] = "test.exe sample All 15";
char *lpStr3;
lpStr3 = buffer_3;
// Path_4 to search for file arguments (no arguments):
char buffer_4[ ] = "test.exe";
char *lpStr4;
lpStr4 = buffer_4;
cout << "The path passed to the function was : " << lpStr1 <<
"\nThe arg(s)found in path 1 were : " << PathGetArgs(lpStr1) << endl;
cout << "\nThe path passed to the function was : " << lpStr2 <<
"\nThe arg(s)found in path 2 were : " << PathGetArgs(lpStr2) << endl;
cout << "\nThe path passed to the function was : " << lpStr3 <<
"\nThe arg(s)found in path 3 were : " << PathGetArgs(lpStr3) << endl;
cout << "\nThe path passed to the function was : " << lpStr4 <<
"\nThe arg(s)found in path 4 were : " << PathGetArgs(lpStr4) << endl;
}
OUTPUT:
===========
The path passed to the function was : test.exe temp.txt sample.doc
The arg(s)found in path 1 were : temp.txt sample.doc
The path passed to the function was : test.exe 1 2 3
The arg(s)found in path 2 were : 1 2 3
The path passed to the function was : test.exe sample All 15
The arg(s)found in path 3 were : sample All 15
The path passed to the function was : test.exe
The arg(s)found in path 4 were :
===========
注意
shlwapi.h 标头将 PathGetArgs 定义为一个别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将中性编码别名与不中性编码的代码混合使用可能会导致编译或运行时错误不匹配。 有关详细信息,请参阅函数原型的
要求
要求 | 价值 |
---|---|
最低支持的客户端 | Windows 2000 Professional、Windows XP [仅限桌面应用] |
支持的最低服务器 | Windows 2000 Server [仅限桌面应用] |
目标平台 | 窗户 |
标头 | shlwapi.h |
库 | Shlwapi.lib |
DLL | Shlwapi.dll(版本 4.71 或更高版本) |