Welcome, Guest.
Please login or register.
Preventing Multiple Instances
Forum Login
Login Name: Create a new account
Password:     Forgot password

XBLite Forum    General Boards    XBLite Programming  ›  Preventing Multiple Instances
Users Browsing Forum
No Members and 1 Guests

Preventing Multiple Instances  This thread currently has 2,650 views. Print Print Thread
1 Pages 1 Recommend Thread
mig25jet
September 5, 2010, 2:54pm Report to Moderator Report to Moderator
Baby Member
Posts: 1
I am working with the sample program: bitmapbutton.x.  The first couple of lines in the Entry() function are as follows:

...

FUNCTION Entry()
    STATIC entry

    IF entry THEN RETURN
    entry = $$TRUE

    Initgui()
...

For some reason this does not seem to work. If I run the program from within XSED or from FileExplorer, it lets me load many
instances of the program.

Question: Does anybody know what is wrong?
Please email me at     chrisk@bell.co.za
Logged Offline
Private Message Private message
XBLiteAdmin
September 6, 2010, 7:59am Report to Moderator Report to Moderator
Administrator Group
Posts: 44
Hi,

The code only prevents one from accidentally calling the Entry() function
more than one time from within the program. It has nothing to do
with preventing running multiple instances of an executable.

If you want to prevent multiple instances of a program, then
you could try using FindWindowA() to see if a certain class window
is found.

D.
Logged Offline
Site Site Private Message Private message Reply: 1 - 2
Guy1954
September 19, 2010, 3:24pm Report to Moderator Report to Moderator

Medium Member
Posts: 187
Hi,

In viXen, I use the "Terminator:

  ' ========================================================================
  ' The Terminator
  ' ==============

  ' make sure only one instance of current application is active at a time
  eventName$ = PROGRAM$ (0) + "_is_active"

  ' create event eventName$
  SetLastError (0)
  hEvent_is_active = CreateEventA (0, 0, 0, &eventName$)
  errNum = GetLastError ()

  IFZ hEvent_is_active THEN
    msg$ = "Can't create event " + eventName$ + " with 'CreateEventA (0, 0, 0, &eventName$)'"
    msg$ = msg$ + $$CRLF$ + "error num " + STRING$ (errNum)
    msg$ = msg$ + $$CRLF$ + "Can't be sure only one instance of current application is active at a time"
    XstAlert (msg$)
  ELSE
    ' created event eventName$
    ' already exists for current application?
    IF errNum = $$ERROR_ALREADY_EXISTS THEN
      ' release event
      SetLastError (0)
      ret = CloseHandle (hEvent_is_active)
      IFZ ret THEN    ' error
        errNum = GetLastError ()
        msg$ = "Can't release event " + eventName$ + " with 'CloseHandle (hEvent_is_active)'"
        msg$ = msg$ + $$CRLF$ + "error num " + STRING$ (errNum)
        XstAlert (msg$)
      END IF
      '
      ' terminate current application
      XstAbend ("Application TERMINATED! " + PROGRAM$ (0) + " is already active")
    END IF
  END IF
  ' ========================================================================

Bye! Guy
Logged Offline
Site Site Private Message Private message Reply: 2 - 2
1 Pages 1 Recommend Thread
Print Print Thread

XBLite Forum    General Boards    XBLite Programming  ›  Preventing Multiple Instances

Thread Rating
There is currently no rating for this thread