网站首页  词典首页

请输入您要查询的函数:

 

术语 commandlinetoargvw
释义 CommandLineToArgvW
语法:
LPWSTR *CommandLineToArgvW( LPCWSTR lpCmdLine,
int *pNumArgs
);
CommandLineToArgvW功能
解析一个Unicode字符串和命令行返回一个指针数组的命令行参数,连同这种说法计数的方式,类似于标准C运行时argv和argc价值。
参数
lpCmdLine
[in]
指向一个以空结尾的Unicode字符串,包含完整的命令行。如果这个参数是一个空字符串的函数返回当前的路径可执行文件。
pNumArgs
[out]指向一个int,它接收返回的数组元素,类似到argc数量。
返回值
一个一个LPWSTR指针,类似的argv数组的指针。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
由CommandLineToArgvW返回的地址是在一个LPWSTR指针数组的第一个元素,在此数组指针的数目是由pNumArgs表示。每到一个空指针结尾的Unicode字符串表示一个单独的参数在命令行中发现。
CommandLineToArgvW分配一个供该参数字符串的指针连续的内存块,并为自己的字符串参数,调用应用程序必须释放的参数列表所使用的内存时,不再需要。要释放的内存,使用单一调用LocalFree功能。
如需有关参数argv和argc公约信息,请参见参数定义和解析C + +的命令行参数。
该GetCommandLineW函数可用于获得命令行字符串作为参数的lpCmdLine适合。
此函数接受的命令行中包含的程序名称,该程序的名称可以在引号或不封闭的。
CommandLineToArgvW有一个反斜杠字符的解释时,特别是由一个引号字符之后(“),如下:
一个引号产生一个引号后?反斜杠后为2n反斜杠。
(2n)的+一个引号随后又产生了一个引号后?反斜杠1反斜杠。
?反斜线没有遵循一个引号只是生产?反斜杠。
例如
下面的示例演示如何解析一个Unicode命令行字符串。释放的代码为在出口参数列表内存。

#include
#include
#include
int __cdecl main()
{
LPWSTR *szArglist;
int nArgs;
int i;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\\n");
return 0;
}
else for( i=0; i // Free memory allocated for CommandLineToArgvW arguments.
LocalFree(szArglist);
return(1);
}
功能信息
最低DLL版本 Shell32.dll 6.0或更高版本
自定义ImplementationNo
HeaderShellapi.h
import libraryShell32.lib
最低经营systemsWindows NT Workstation的3.5时,Windows NT服务器3.5,Windows 2000专业版,Windows 2000服务器时,Windows XP,Windows Server 2003的
UnicodeImplemented为Unicode版本。
==英文原文==CommandLineToArgvW Function
Parses a Unicode command line string and returns an array of pointers to the command line arguments, along with a count of such arguments, in a way that is similar to the standard C run-time argv and argc values.
Syntax
LPWSTR *CommandLineToArgvW( LPCWSTR lpCmdLine,
int *pNumArgs
);
Parameters
lpCmdLine
[in]
Pointer to a null-terminated Unicode string that contains the full command line. If this parameter is an empty string the function returns the path to the current executable file.
pNumArgs
[out] Pointer to an int that receives the number of array elements returned, similar to argc.
Return Value
A pointer to an array of LPWSTR pointers, similar to argv.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
Remarks
The address returned by CommandLineToArgvW is the first element in an array of LPWSTR pointers; the number of pointers in this array is indicated by pNumArgs. Each pointer to a null-terminated Unicode string represents an individual argument found on the command line.
CommandLineToArgvW allocates a block of contiguous memory for pointers to the argument strings, and for the argument strings themselves; the calling application must free the memory used by the argument list when it is no longer needed. To free the memory, use a single call to the LocalFree function.
For more information about the argv and argc argument convention, see Argument Definitions and Parsing C++ Command-Line Arguments .
The GetCommandLineW function can be used to get a command line string that is suitable for use as the lpCmdLine parameter.
This function accepts command lines that contain a program name; the program name can be enclosed in quotation marks or not.
CommandLineToArgvW has a special interpretation of backslash characters when they are followed by a quotation mark character ("), as follows:
2n backslashes followed by a quotation mark produce n backslashes followed by a quotation mark.
(2n) + 1 backslashes followed by a quotation mark again produce n backslashes followed by a quotation mark.
n backslashes not followed by a quotation mark simply produce n backslashes.
Example
The following example demonstrates how to parse a Unicode command-line string. The code frees the memory for the argument list at exit.
#include
#include
#include
int __cdecl main()
{
LPWSTR *szArglist;
int nArgs;
int i;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\\n");
return 0;
}
else for( i=0; i // Free memory allocated for CommandLineToArgvW arguments.
LocalFree(szArglist);
return(1);
}
Function Information
Minimum DLL VersionShell32.dll version 6.0 or later
Custom ImplementationNo
HeaderShellapi.h
Import libraryShell32.lib
Minimum operating systemsWindows NT Workstation 3.5, Windows NT Server 3.5, Windows 2000 Professional, Windows 2000 Server, Windows XP, Windows Server 2003
UnicodeImplemented as Unicode version.
==原始网址==http://msdn.microsoft.com/en-us/library/bb776391(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:25:16