- Aug
- 2,294
- 111
I was having problems using the Kernel32.dll GetCommandLine function via @WINAPI, so I developed an alternate method using PowerShell.
Here is the .BTM;
As with my original solution, you can run this .BTM from the;
* TCC Command Line
* TCC Debugger
* CMDebug Debugger
...to see the different command lines returned.
For myself, I have added the following to my TCSTART.BTM;
Next, I have added the following to my function.lst that I call from TCSTART.BTM;
Now, when I need the command line, I can (example);
...from TCC, BDEBUGGER, IDE, TCC-RT, etc.
Joe
Here is the .BTM;
Code:
@setlocal
@echo off
type <<- endtext > GetCommandLine.ps1
[Environment]::CurrentDirectory = $pwd
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class Kernel32
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern System.IntPtr GetCommandLine();
}
'@
endtext
pshell GetCommandLine.ps1
if exist GetCommandLine.ps1 del /q GetCommandLine.ps1
pshell /s "$theptr = [kernel32]::GetCommandLine()"
pshell /s "[Runtime.InteropServices.Marshal]::PtrToStringAuto($theptr)"
endlocal
As with my original solution, you can run this .BTM from the;
* TCC Command Line
* TCC Debugger
* CMDebug Debugger
...to see the different command lines returned.
For myself, I have added the following to my TCSTART.BTM;
Code:
type <<- endtext > GetCommandLine.ps1
[Environment]::CurrentDirectory = $pwd
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class Kernel32
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern System.IntPtr GetCommandLine();
}
'@
endtext
pshell GetCommandLine.ps1
if exist GetCommandLine.ps1 del /q GetCommandLine.ps1
Next, I have added the following to my function.lst that I call from TCSTART.BTM;
Code:
GetCommandLine=%@pshell[$theptr = [kernel32]::GetCommandLine(); [Runtime.InteropServices.Marshal]::PtrToStringAuto($theptr)]
Now, when I need the command line, I can (example);
Code:
e:\utils>echo %@getcommandline[]
"C:\Program Files\JPSoft\TCMD24\TCC.EXE"
...from TCC, BDEBUGGER, IDE, TCC-RT, etc.
Joe