Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
PUBLIC VAR's
Message
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Title:
Miscellaneous
Thread ID:
00455067
Message ID:
00455124
Views:
29
>>Hi All,
>>
>>In my MAIN PRG, I declared PUBLIC Variable that I release it at the end of my Application run. I use this variable to check if the application is already running.
>>
>>If I run the app twice, I don't find the public var. (I use the TYPE() function for that...), What Am I doing wrong ?
>>
>>Thanks,
>>
>>Gadi
>
>Ed Rauh shows how to use the CreateEvent() API call to do this. See the API section for a description and code. There are a number of other ways, however, to accomplish this. Another API solution involves creating a mutex. You could also use DDE.

I save Ed's code in our ClassLib, it works fine:
********************************************************************
*  Description.......: EnsureOneInstance
*  Calling Samples...: Use this code in the main program of application, if you want to ensure only one instance of it
*  Parameter List....: 
*  Created by........: Ed Rauh 
*  Modified by.......: 
********************************************************************
DECLARE INTEGER CreateEvent IN WIN32API ;
   INTEGER lpEventAttributes, ;
   SHORT bManualReset, ;
   SHORT bInitialState, ;
   STRING @ lpName
DECLARE INTEGER GetLastError IN Win32API
DECLARE CloseHandle IN Win32API INTEGER hObject
nEh = CreateEvent(0,0,1, PROGRAM(0) + '.EVENT')
IF GetLastError() = 183 OR nEh = 0
   *  There's an instance running already (183) or the Event can't be defined
   *  So don't do it;  do release the handle, since it's harmless and should
   *  be done rather than relying on Windows to clean up after itself
   =CloseHandle(nEh)
   QUIT
ENDIF
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform