如何编一个可执行程序实现一个带参数的DOS命命?
如何编一个可执行程序实现一个带参数的DOS命命? 如 del.exe f.dt -r -x
6月4日
关于API GetCommandLine的使用
算留做参考资料吧,免得有人继续不会用还查不到正确的资料。
Public Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As String, ByVal Source As Long, ByVal Length As Long)
Function fGetCommandLine() As String
Dim lRet As Long, sCmd As String
lRet = GetCommandLine
If lRet > 0 Then
sCmd = String(256, 32)
CopyMemory sCmd, lRet, Len(sCmd)
sCmd = Mid(sCmd, 1, InStr(1, sCmd, Chr(0)) - 1)
End If
fGetCommandLine = sCmd
' 关于API GetCommandLine的使用说明
' MSDN:
' The return value is a pointer to the command-line string for the current process.
' 返回字符串指针(指向当前命令行缓冲区的一个指针),并非字符串,API Viewer的声明是错误的。
' References:
' http://topic.
End Function
MSDN98(for VC++6, 1033):
GetCommandLine
The GetCommandLine function returns a pointer to the command-line string for the current process.
LPTSTR GetCommandLine(VOID)
Parameters
This function has no parameters.
Return Values
The return value is a pointer to the command-line string for the current process.
Remarks
ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows and Windows NT.
See Also
Processes and Threads Overview, Process and Thread Functions, CreateProcess, WinMain
http://multiple001.spaces.