共用方式為


PathGetArgsA 函式 (shlwapi.h)

尋找指定路徑內的命令行自變數。

語法

LPCSTR PathGetArgsA(
  [in] LPCSTR 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 標頭會根據 UNICODE 預處理器常數的定義,將 PathGetArgs 定義為自動選取此函式的 ANSI 或 Unicode 版本。 混合使用編碼中性別名與非編碼中性的程序代碼,可能會導致編譯或運行時間錯誤不符。 如需詳細資訊,請參閱函式原型的 慣例。

要求

要求 價值
最低支援的用戶端 Windows 2000 Professional、Windows XP [僅限傳統型應用程式]
支援的最低伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平臺 窗戶
標頭 shlwapi.h
連結庫 Shlwapi.lib
DLL Shlwapi.dll (4.71 版或更新版本)