Recent posts

#1
OxygenBasic Examples / Re: Asm multiplication
Last post by Frank Brübach - Yesterday at 08:54:18 PM
Found the solution :)
Wanted only to make this example for using a Powerbasic a Like Style with Message Box and a result of two values Here multiplication

Oxygen basic

' multiplication of two values
'
Declare Function MessageBox Lib "user32.dll" alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long



' 1) '- multiply go asm ------------------- //     
'

byte val1
byte val2
int result ''resd 1
   
    val1=4
    val2=6 '

     mov eax,val1 
     mov eax,val2  ''multiply eax by ebx  "
     mul val1 'ebx 
     mov result,eax

     
'print "the result of val1*val2 is " + str(result) '24


zstring tit[] = " PowerBASIC"
string msg[] = " hello my powerbasic friends " + str(result)

push 2 ' 0
addr eax,tit
push eax
addr eax,msg
push eax
addr eax,result
push 0

call MessageBox
mov eax, msg

#2
OxygenBasic Examples / Re: Asm multiplication
Last post by Frank Brübach - Yesterday at 08:08:19 PM
Hello...

New question How I  can add the result of multiplication to the call Message Box Line so result get shown in Message Box too?


' multiplication of two values
'
Declare Function MessageBox Lib "user32.dll" alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

zstring tit[] = " PowerBASIC"
zstring msg[] = " hello my powerbasic friends"

byte val1
byte val2
int result ''resd 1
   
    val1=4
    val2=6 '

' 1) '- multiply go asm ------------------- //     
'
mov eax,val1 
mov eax,val2  ''multiply eax by ebx  "
mul val1 'ebx 
mov result,eax

'- multiply go asm ------------------- //

'
' 2) how I can add the result of "mov result,eax" to the Call MessageBox  ?
'------------ messagebox go ---------- //
'32bit asm
push 2 ' 0 '2
addr eax,tit
push eax
addr eax,msg
push eax
push 0
call MessageBox ' here should be the result of multiply mov result,eax

'------------ messagebox go ---------- //

print "the result of val1*val2 is " + str(result) '24

#3
OxygenBasic / Re: Hide exec process
Last post by Nicola - Yesterday at 07:21:59 PM
Hi
I tried again and now it's ok. I had left another command that opened the cmd window, the DOS one. I fixed it by doing this:

string cancellaPdf ="cmd.exe /c del "+pdf
if FileExists(pdf)=1 then exechide(cancellaPdf,1)
String riga=prodir + " -out pdf -ratio -resize 1200 -overwrite -c 5 -q "+qualita+" -o " +qu+pdf+qu+ " " +qu+f+qu
[font=Verdana, Arial, Helvetica, sans-serif]int valu=exechide(riga,1) [/font]

Exechide works.
#4
🚨 Watchdog Functionality:

This script acts as a watchdog, ensuring the main script stays within the communicated time frame. Use this template in your scripts where a watchdog is needed to monitor the main script's processing.

Example Scenario:
Let's take this case: we have a Dictate Script that calls WHISPER from OpenAI. Sometimes WHISPER is just busy and not responding. To prevent the script from "waiting forever" (which it would not do anyway), we can embed the functionality in a "20 Seconds Watchdog".

If the script does not return within the specified 20 seconds, the Main Script is killed, and the Watchdog will end itself automatically with the Main Script.

General Usage:
' Set the Watchdog to 20 Seconds
%SetWatchdog 20

' After using the Watchdog, switch it off
%ClrWatchdog


Sample Use:
'-----------------------------------------------------------
' Dictate
'-----------------------------------------------------------
:But_Dictate
%SetWatchdog 20
GSB.HiColor
GSB.Dictate
GSB.LoButton
%ClrWatchdog
RET.

Usage Instructions:
The code below is ready to be used. Call the Subprogram that starts the Watchdog-Robot. Then use:

The Watchdog will automatically end itself when the Main Script ends.

Watchdog-Code:
'-----------------------------------------------------------
' Dictate
'-----------------------------------------------------------
:But_Dictate
%SetWatchdog 2
GSB.HiColor
GSB.Dictate
GSB.LoButton
%ClrWatchdog
RET.

'**********************************************
' PRR./PRE./PRV. - Watchdog
' This script demonstrates a simple watchdog timer
' using the $$TIM variable to monitor the main script.
'
' Usage:
' - Set $$TIM to a non-zero value to start the watchdog.
' - The watchdog monitors the elapsed time.
' - If $$TIM is zero, the watchdog is off.
' - If the elapsed time exceeds $$TIM, an action is taken.
'**********************************************
:Watchdog_Start
MOD.New|Watchdog
' Variables Initialization
VAR.$$MWH=#cbw#
' Default State is off
VAR.$$TIM=0
'-----------------------------------------------------------
' Parallel Robot Routine
PRR.0
  MOD.Enter|Watchdog
  ' Print robot information
  'PRT.I am (Parallel-)Robot-Nr. #pri#.
  'PRT.I am Son #pri# of $$MWH.

  :Loop
  PRT.Watchloop A
    ' Wait for timer value to be set
  WFV.$$TIM|3
  JIZ.$$TIM|off

    ' Record the start datetime
  $$STA=#dtime#

    ' Main watchdog loop
  :WatchdogLoop
  PRT.Watchloop B: $$TIM
   ' Pause for a short period
  PAU.1

      ' Calculate the elapsed time
  CAL.$$CUT=(#dtime#-$$STA)
  PRT.Test: $$CUT>$$TIM
      ' Check if the elapsed time exceeds the timer value
  IVV.$$CUT>$$TIM
    ' Print the elapsed time and the timer value
    PRT.Watchdog-Timeout: $$CUT>$$TIM

        ' Get and execute the command
    GDF.hp|$$MWH|$$PID
    CPR.$$PID
  EIF.

  ' Check if the timer is reset to zero (watchdog off)
  JIZ.$$TIM|off
      ' Repeat the watchdog loop
  JMP.WatchdogLoop

    ' Off condition handling
  :off
      ' Pause for 1 second
  PAU.1

      ' Jump back to the beginning of the loop
  JMP.Loop

  END.

  ' Set return value for the main program
PRE.$$WDG|0
MOD.Copy to Last|$$WDG
'-----------------------------------------------------------
MOD.Return
RET.

: %SetWatchdog 1
MOD.Enter|Watchdog
VIN.$$TIM=§§§01
PRV.$$WDG|$$TIM
MOD.Return
END%

: %ClrWatchdog
MOD.Enter|Watchdog
VIN.$$TIM=0
PRV.$$WDG|$$TIM
MOD.Return
END%


Hint: From Update 06/05/24 Parallel-Robots inherit not only all Variables but also all Module-Spaces from their "Father Robot". If you have an older version use "MOD.Enter|1" or "MOD.New|Watchdog" instead of "MOD.Enter|Watchdog". I recommend to ask for the newest Update to use this feature.
#5
Proof of an Afterlife: the Shared-Death Experience with Raymond Moody and Paul Perry

New Thinking Allowed with Jeffrey Mishlove
11 oct 2023

#6
OxygenBasic / Re: Hide exec process
Last post by Nicola - Yesterday at 10:17:20 AM
Thank you Theo. I will definitely try them!!
 SEE_MASK_NO_CONSOLE has the numeric value 0x08000000 in hexadecimal or 134217728 in decimal. This value is used to set the appropriate option when creating a new process using code.
it's the constant I mentioned in the first post....

@Charles
No, I start an external third-party program.
#7
OxygenBasic / Re: Hide exec process
Last post by Theo Gottwald - Yesterday at 08:17:57 AM
There are additional options for starting programs without displaying the CMD console in PowerBASIC.

One of the alternatives is using the ShellExecuteEx function, which provides more control and flexibility. This function is particularly useful if you need to open documents or URLs with their associated applications, or if you need to start a program with more specific parameters.

Here's how you can implement the ShellExecuteEx function to start a program without showing the CMD console:

Step-by-Step Implementation using ShellExecuteEx

Define the necessary constants and structures:

#COMPILE EXE
#DIM ALL

#INCLUDE "WIN32API.INC"

TYPE SHELLEXECUTEINFO
  cbSize          AS DWORD
  fMask           AS DWORD
  hwnd            AS DWORD
  lpVerb          AS ASCIIZ PTR
  lpFile          AS ASCIIZ PTR
  lpParameters    AS ASCIIZ PTR
  lpDirectory     AS ASCIIZ PTR
  nShow           AS LONG
  hInstApp        AS DWORD
  lpIDList        AS ANY PTR
  lpClass         AS ASCIIZ PTR
  hkeyClass       AS DWORD
  dwHotKey        AS DWORD
  hIcon           AS DWORD
  hProcess        AS DWORD
END TYPE

%SEE_MASK_NOCLOSEPROCESS = &H00000040
%SEE_MASK_NO_CONSOLE     = &H08000000
%SW_HIDE                 = 0

Create the ShellExecNoConsole function to execute the command:

FUNCTION ShellExecNoConsole (BYVAL Command AS STRING, BYVAL Params AS STRING) AS LONG
  DIM sei AS SHELLEXECUTEINFO
  DIM result AS LONG

  sei.cbSize = SIZEOF(sei)
  sei.fMask = %SEE_MASK_NOCLOSEPROCESS OR %SEE_MASK_NO_CONSOLE
  sei.hwnd = %NULL
  sei.lpVerb = VARPTR(STRPTR("open"))
  sei.lpFile = VARPTR(STRPTR(Command))
  sei.lpParameters = VARPTR(STRPTR(Params))
  sei.lpDirectory = %NULL
  sei.nShow = %SW_HIDE

  result = ShellExecuteEx(sei)

  IF result THEN
    ' Wait for the process to complete, if needed
    WaitForSingleObject(sei.hProcess, %INFINITE)
    CloseHandle(sei.hProcess)
  END IF

  FUNCTION = result
END FUNCTION

Call the ShellExecNoConsole function in your main program:


FUNCTION PBMAIN () AS LONG
  DIM command AS STRING
  DIM params AS STRING
  command = "notepad.exe"  ' Example command
  params = ""              ' Example parameters, if any

  IF ShellExecNoConsole(command, params) THEN
    MSGBOX "Process started successfully without a visible window.", %MB_OK, "Info"
  ELSE
    MSGBOX "Failed to start the process.", %MB_OK, "Error"
  END IF
END FUNCTION

Explanation

SHELLEXECUTEINFO: This structure is necessary for configuring the ShellExecuteEx function.

SEE_MASK_NOCLOSEPROCESS and SEE_MASK_NO_CONSOLE: These flags ensure the process starts without creating a console window and that you can wait for the process to complete if needed.

ShellExecuteEx: This function starts the process with the specified attributes and more control compared to CreateProcess.

WaitForSingleObject: This function waits for the process to complete if needed. You can remove it if you don't need to wait for the process to finish.

Using ShellExecuteEx provides additional options and flexibility for starting programs without a visible console, making it a robust alternative to CreateProcess. This method is particularly useful for more complex scenarios where you need finer control over the execution of the program.
#8
OxygenBasic / Re: Hide exec process
Last post by Charles Pegge - Yesterday at 07:31:36 AM
Hi Nicola,
Are these your own processes/programs?
#9
OxygenBasic / Re: Hide exec process
Last post by Nicola - May 24, 2024, 09:58:28 PM
... I'm a little disappointed with the result
#10
OxygenBasic / Hide exec process
Last post by Nicola - May 24, 2024, 09:38:56 PM
Hi
I was looking for a way to keep the CMD console from appearing when I start some programs with the exec command...
I found this system by inserting the constant CREATE_NO_WINDOW in the createprocess...
I wondered if this was the best method...

In sysutil I duplicated the existing function "exec" with this:
  function ExecHide(string c, int wait=0) as int
  ==========================================
  STARTUPINFO infs
  PROCESS_INFORMATION infp
  ' [color=#0000ff]CREATE_NO_WINDOW [/color]= 134217728
  CreateProcess null,c,0,0,0,134217728,0,0,@infs,@infp
  if wait
    WaitForMultipleObjects 1,@infp.hthread,1,-1
  end if
  GetExitCodeProcess(infp.hProcess,@function)
  CloseHandle infp.hProcess
  CloseHandle infp.hThread
  return 0
  end function

Cheers