Code: Select all
#cmdline "-exx"
dim as integer ptr p
print *p
Code: Select all
#cmdline "-exx"
dim as integer ptr p
print *p
Thank you for your research and efforts on this thread, but my goal is not to solve this on my system, but from within the software, because I can't expect every user to change their system just to make the software run properly.srvaldez wrote: ↑Jun 06, 2023 21:24 UEZ
here's a quick and easy way for your console program to run using the conhost, create a shortcut of your program, then righr-click on the shortcut and select properties, click on the options tab and put a check mark on Use legacy console, that's it
<edit> after you made the short-cut and checked the legacy option you can delete the short-cut and your program will still use the legacy console, although for distribution, if your program is run on a different PC then it would probably require the short-cut
Code: Select all
...
Function _WinAPI_TerminateProcess(iPID As Integer, iExitCode As Integer = 0, bInheritHandle As Boolean = FALSE) As Boolean
Dim As Long dwDesiredAccess = PROCESS_TERMINATE
Dim As Handle hProcess = OpenProcess(dwDesiredAccess, bInheritHandle, iPID)
If hProcess = Null Then Return False
TerminateProcess(hProcess, iExitCode)
CloseHandle(hProcess)
Return True
End Function
Function _WinAPI_GetProcessName(iPid As DWORD) As String
Dim As HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, iPid)
If hSnapshot = 0 Then Return ""
Dim As PROCESSENTRY32W tPROCESSENTRY32W
tPROCESSENTRY32W.dwSize = Sizeof(PROCESSENTRY32W)
Process32FirstW(hSnapshot, @tPROCESSENTRY32W)
While True
If tPROCESSENTRY32W.th32ProcessID = iPid Then Exit While
If Process32NextW(hSnapshot, @tPROCESSENTRY32W) = 0 Then Exit While
Wend
CloseHandle(hSnapshot)
Return tPROCESSENTRY32W.szExeFile
End Function
Function _WinAPI_GetParentProcess(iPID As Integer = 0) As Integer
Dim As DWORD pid = Iif(iPID = 0, GetCurrentProcessId(), iPID), pid_parent = 0
Dim As HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
Dim As PROCESSENTRY32 tPROCESSENTRY32
tPROCESSENTRY32.dwSize = Sizeof(tPROCESSENTRY32)
Process32First(hSnapshot, @tPROCESSENTRY32)
While TRUE
If tPROCESSENTRY32.th32ProcessID = pid Then
pid_parent = tPROCESSENTRY32.th32ParentProcessID
Exit While
End If
Process32Next(hSnapshot, @tPROCESSENTRY32)
Wend
CloseHandle(hSnapshot)
Return pid_parent
End Function
...
Sub GetCommandLineArguments(Byref sArguments As String)
Dim As Ushort i = 1
Dim As String s
While True
s = Command(i)
If Len(s) = 0 Then Exit While
sArguments &= s & " "
i += 1
Wend
End Sub
...
hConsole = GetConsoleWindow()
Dim As Wstring * 4096 sClassname
GetClassNameW(hConsole, @sClassname, 4096)
Dim Shared As Integer iOldStyle
iOldStyle = GetWindowLong(hConsole, GWL_STYLE)
Dim As String sArguments = " "
GetCommandLineArguments(sArguments)
If (SendMessageW(hConsole, WM_GETICON, Iif(OS.dwBuildNumber < 9200, 1, 0), 0) = 0 And sClassname = "PseudoConsoleWindow") Then 'restart app in CMD window
#ifdef __FB_64BIT__
Shell("conhost.exe """ & Command(0) & """ restart" & sArguments)
#else
? "Please open this app in command-line window (CMD) - Terminal window is not support yet!"
Sleep()
#endif
FreeConsole()
End 1000
Endif
If Command(1) = "restart" Then
Dim As String exeName = Mid(Command(0), Instrrev(Command(0), "/") + 1, Len(Command(0)))
Dim As Ubyte countParentPIDs = 0
Dim As Integer iPID, parentPID = _WinAPI_GetParentProcess()
While True
iPID = _WinAPI_GetParentProcess(parentPID)
If _WinAPI_GetProcessName(iPID) <> "cmd.exe" Then
parentPID = iPID
countParentPIDs += 1
If countParentPIDs > 5 Then Exit While
Else
_WinAPI_TerminateProcess(iPID, 0, True)
Exit While
Endif
Wend
Endif
Code: Select all
Sub scrollpage(s As String)
Var y=Hiword(Width)
Dim As String i
Redim As long page(1 To 1)
page(1)=0
For z As long=0 To Len(s)-1
Print Chr(s[z]);
If Csrlin>y-2 Then
Redim Preserve page(1 To Ubound(page)+1)
page(Ubound(page))=z
print "(Use up/down arrow keys, PROGRESS:"+" ";z;" of ";len(s);" characters)"
Sleep
do
i=Inkey
' sleep 1
loop until i=chr(27) or i=Chr(256)+"H" or i=chr(256)+"P"
If i=Chr(27) Then Exit Sub
If i=Chr(256)+"H" Then ''UP ARROW
If Ubound(page)>2 Then
z=page(Ubound(page)-2)
Redim Preserve page(Ubound(page)-2)
If Ubound(page)=1 Then z=-1
Else
'down arrow
z=-1
End If
End If
Cls
Locate 1
End If
If z=Len(s)-1 Then
Print "end of file"
Sleep
If Inkey=Chr(256)+"H" Then Cls:scrollpage(s)
End If
Next
End Sub
Function PipeToStringDC( s As String)As String
Var f=Freefile
Open Pipe s For Binary Access Read As #f
function=Input(100000000,f)
Close #f
End Function
var h=PipeToStringDC("tree " +"""c:/Program Files"""+" /F /A")
'var h=PipeToStringDC("tree " +"c:/windows"+" /F /A")
scrollpage( h)
The reason is simple: I coded Radio Stations which uses the command-line window (CMD) to display some information about the current played song which is hosted either on remix.kwed.org or amigaremix.com (two different apps!).