Windows API

ID #1051

How to deny recurring run of application?

Most reliable method is using of named kernel object - event or mutex. Even if application hangs with GPF kernel will free such resource automatically.

Example

MAP
  MODULE('user32')
    api_CreateMutex(UNSIGNED _lpMutexAttr,SIGNED _bInitialOwner,*CSTRING _lpName), |
SIGNED,RAW,PASCAL,NAME('CreateMutexA')
    api_ReleaseMutex(UNSIGNED _hMutex),SIGNED,PASCAL,PROC,NAME('ReleaseMutex')
    api_CloseHandle(UNSIGNED _hObject),SIGNED,PASCAL,PROC,NAME('CloseHandle')
  END
END
! Global data
GLO:lpMutexName  CSTRING('This_Is_My_Mutex')
GLO:loAppMutex   LONG
CODE
GLO:loAppMutex = api_CreateMutex(0,TRUE,Glo:lpMutexName)
IF api_GetLastError() = 183
  MESSAGE('Application is alredy running','Attention',ICON:Asterisk)
  RETURN
END
Main ! Main procedure
IF GLO:loAppMutex
  api_ReleaseMutex(GLO:loAppMutex)
  api_CloseHandle(GLO:loAppMutex)
END
Categories for this entry

Tags: application, mutex, recurring run

Related entries:

Last update: 2007-07-17 10:03
Author: Aleksey Timkov
Revision: 1.0

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 0 out of 5 (0 Votes )

completely useless 1 2 3 4 5 most valuable

You can comment on this entry