未分类--Windows API--CommandLineToArgvW

150 篇文章 0 订阅
31 篇文章 0 订阅

原文来自MSDN Library for Visual Studio 2008 SP1,翻译部分仅为个人观点,想要看更多信息请看MSDN,如有版权问题请联系QQ 643166601,邮件643166601@qq.com

 

CommandLineToArgvW Function

--------------------------------------------------------------------------------

Parses a Unicode command line string and returns an array of null-terminated Unicode strings.
解析一个Unicode命令行字符串并且返回一个以null结尾的Unicode字符串数组。
The strings contain the individual arguments found in that command line, and a count of arguments, similar to the standard C run-time argv and argc values.
这个字符串包含在命令行中单独的参数,和参数的计数,类似于标准C运行时的argv 和 argc值。
Syntax

LPWSTR *CommandLineToArgvW(         
LPCWSTR lpCmdLine,
int *pNumArgs
);
Parameters

lpCmdLine
[in] A pointer to a null-terminated Unicode string containing the full command line.
一个指向以null结尾的Unicode字符串包含在完整的命令行。
An application will usually directly pass on the value returned by a call to the GetCommandLineW function.
一个应用程序将通常通过调用GetCommandLineW函数的返回值直接传递。
If this parameter is the empty string (""), the function returns the path to the current executable file.
如果这个参数是一个空字符串(""),这个函数返回当前可执行文件的路径。
pNumArgs
[out] A pointer to a variable of type int that receives the number of array elements returned.
一个指针指向int类型的变量它取回返回数组的数量。
Return Value

A pointer to an array of null-terminated Unicode strings representing the individual arguments found on the command line.
一个指针指向以null结尾的Unicode字符串数组代表这个独立参数在命令上找到。
The first element contains the program name; each subsequent element contains one argument.
这个第一个元素包含程序名称,随后的每个元素包含一个参数。
If the function fails, the return value is NULL.
如果这个函数失败,返回值是NULL。
To get extended error information, call GetLastError.
去获得额外的错误信息请调用GetLastError。

Remarks

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.
去释放内存,使用一个单独的LocalFree函数。
This function accepts command lines containing 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:
当它们通过引号字符(")时CommandLineToArgvW有一个指定的反斜杠字符解释,如下
2n backslashes followed by a quotation mark produce n backslashes followed by a quotation mark.
2n个反斜杠后续通过一个引号产生n个反斜杠跟着一个引号
(2n) + 1 backslashes followed by a quotation mark again produce n backslashes followed by a quotation mark.
(2n) + 1 个反斜杠后续一个引号再一次产生n个反斜杠跟着是一个引号。
n backslashes not followed by a quotation mark simply produce n backslashes.
n个反斜杠不能后序一个引号类似长生n个反斜杠。
Example

The following example demonstrates how to parse a Unicode command-line string. The code frees the memory for the argument list at exit.

Show Example

#include <windows.h>
#include <stdio.h>
#include <shellapi.h>

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<nArgs; i++) printf("%d: %ws\n", i, szArglist[i]);

// Free memory allocated for CommandLineToArgvW arguments.

   LocalFree(szArglist);

   return(1);
}
Function Information

Minimum DLL Version Shell32.dll version 6.0 or later
Custom Implementation No
Header Shellapi.h
Import library Shell32.lib
Minimum operating systems Windows NT Workstation 3.5, Windows NT Server 3.5, Windows 2000 Professional, Windows 2000 Server, Windows XP, Windows Server 2003
Unicode Implemented as Unicode version.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值