Page 1 of 1

DC_IsAppRunning() and CRT window

Posted: Tue Sep 30, 2025 3:35 am
by slobodan1949
Dear Roger,
is it possible to correct the function DC_IsAppRunning("XbpPmtClass","",appname(),.T.)
which will work correctly with Xbase++ CRT APP Window - SetAppWindow() when the
application does not use APPSYS.PRG. If possible, I would like to ask for it.

In my example, which I am attaching, the function DC_IsAppRunning does not work correctly,
while the function IntCnt(.T.) written in 2008 by Michael McVicker works correctly.
Also, the function IntCnt(.T.) works in the control: MsgBox(), ConfirmBox(), AlertBox()...
I am attaching the source code of the test program for both functions and the code
for the function IntCnt() in the RUNAPP.ZIP.

Note:
Until recently I thought that this with CRT windows was no longer needed by anyone.
But the need for this technique arose when training new users of
Alaska Xbase++ and eXpress++ who finally want to transfer their existing Clipper
applications to Xbase++ and eXpress++, because 64-bit Windows 11
no longer allows further play with Clipper.

Re: DC_IsAppRunning() and CRT window

Posted: Tue Sep 30, 2025 5:41 pm
by rdonnay
Here is another way to do this:

Code: Select all

RunShell('/C TaskList.Exe /V /FO CSV > tasklist.csv' )

aTasks := DC_Csv2Array('tasklist.csv')

nFound := AScan(aTasks,{|a|a[1]=='RUNAPP.EXE'})
nFound := AScan(aTasks,{|a|a[1]=='RUNAPP.EXE'},nFound+1)

  IF nFound > 0
    Confirmbox(,"PROGRAM HAS ALREADY STARTED" + chr(13)+;
                "RESTART IS NOT POSSIBLE"     + chr(13)+;
               appname(.t.),;
               "1 STOP PROGRAM START",;
               XBPMB_OK,XBPMB_CRITICAL,XBPMB_SYSMODAL)
     QUIT
  Else

    Confirmbox(,"Instance: "+ Str(nFound) + chr(13)+;
               appname(.t.),;
               "1 PROGRAM IS STARTED",;
               XBPMB_OK,XBPMB_INFORMATION,XBPMB_SYSMODAL)
  EndIF

Re: DC_IsAppRunning() and CRT window

Posted: Fri Oct 10, 2025 4:14 am
by slobodan1949
Thanks for the new technique.

Re: DC_IsAppRunning() and CRT window

Posted: Fri Oct 10, 2025 4:50 am
by Tom
We are using the API-function "CreateMutexA" (KERNEL32.DLL, together with "OpenMutexA") to create a "Mutex" within our application. A Mutex can only created once in a session (so this also works on a Terminal Server) by an application, and if another instance of the same application tries to do so, it fails, so an instance must already be running (we look for the ProcId then). Mutexes can be released at the end (ReleaseMutex), but this is not really needed, since they "die" then. Works great, only few lines of code.

Re: DC_IsAppRunning() and CRT window

Posted: Tue Oct 14, 2025 9:07 am
by slobodan1949
This proved to be effective and simple. Thanks Tom.

Re: DC_IsAppRunning() and CRT window

Posted: Wed Oct 15, 2025 12:11 am
by Tom
:)