Hi all!

I was told that one way to prevent an user to open more than one instance of
an app is to try to FLOCK() a file which is allready locked by the first
instance.

I created a dummy file tlbTmp.dbf with one field only for this purpose. But
the second attempt to FLOCK() doesn´t return .F. as supposed. A file
allready locked can be locked again and again and FLOCK() returns .T.
everytime.

What is the trick to have this solution to work as supposed?

Best regards
Christina

Re: One instance only - VFP8/SP1 by christophe

christophe
Mon Sep 20 05:58:43 CDT 2004

Ch Löfberg,

wasn't it Fopen() instead of Flock() ?

regards
christophe

"Ch Löfberg" <ch.lofberg@telia.com> schreef in bericht
news:cqy3d.3673$d5.28678@newsb.telia.net...
> Hi all!
>
> I was told that one way to prevent an user to open more than one instance
of
> an app is to try to FLOCK() a file which is allready locked by the first
> instance.
>
> I created a dummy file tlbTmp.dbf with one field only for this purpose.
But
> the second attempt to FLOCK() doesn´t return .F. as supposed. A file
> allready locked can be locked again and again and FLOCK() returns .T.
> everytime.
>
> What is the trick to have this solution to work as supposed?
>
> Best regards
> Christina
>
>



RE: One instance only - VFP8/SP1 by Leemi

Leemi
Mon Sep 20 08:54:27 CDT 2004

Hi Christina:

Take a look at the FirstInstance.prg available from Universalthread.com. Go
to www.universalthread.com, click on the Download icon, and choose Visual
FoxPro as the product. In the ID text box of the query page, search for
"9497.

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP9 Public Beta Now Available!! --*
Download the VFP9 beta here: http://msdn.microsoft.com/vfoxpro/

*-- VFP8 HAS ARRIVED!! --*
Read about all the new features of VFP8 here:
http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
Purchase VFP8 here:
http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retired Sept. 30th, 2003

>Hi all!

>I was told that one way to prevent an user to open more than one instance
of
>an app is to try to FLOCK() a file which is allready locked by the first
>instance.

>I created a dummy file tlbTmp.dbf with one field only for this purpose. But
>the second attempt to FLOCK() doesn´t return .F. as supposed. A file
>allready locked can be locked again and again and FLOCK() returns .T.
>everytime.

>What is the trick to have this solution to work as supposed?

>Best regards
>Christina


Re: One instance only - VFP8/SP1 by Josh

Josh
Mon Sep 20 09:04:56 CDT 2004

Why not use Mutex?

FUNCTION Mutex
LPARAMETERS tcCode, tnCount
LOCAL lnHandle

DECLARE INTEGER CreateMutex IN win32api INTEGER Security, INTEGER
Owned,STRING MutexName
DECLARE INTEGER GetLastError IN win32api
DECLARE INTEGER SetLastError IN win32api INTEGER ErrorCode
* DECLARE INTEGER ReleaseMutex IN WIN32API INTEGER nHandle

lnHandle = CreateMutex(0, IIF(VARTYPE(tncoutn)#"N" OR tnCount<=0,1,tnCount),
tcCode)

IF GetLastError() # 0
SetLastError(0)
lnHandle = -1
ENDIF

RETURN lnHandle > 0
ENDFUNC


On Mon, 20 Sep 2004 10:38:00 GMT, "Ch Löfberg" <ch.lofberg@telia.com> wrote:

>Hi all!
>
>I was told that one way to prevent an user to open more than one instance of
>an app is to try to FLOCK() a file which is allready locked by the first
>instance.
>
>I created a dummy file tlbTmp.dbf with one field only for this purpose. But
>the second attempt to FLOCK() doesn´t return .F. as supposed. A file
>allready locked can be locked again and again and FLOCK() returns .T.
>everytime.
>
>What is the trick to have this solution to work as supposed?
>
>Best regards
>Christina
>


---
Remove x's to send.

Re: One instance only - VFP8/SP1 by Ch

Ch
Mon Sep 20 11:26:33 CDT 2004

Josh - I´m new to this, and it looks exciting. A short explanation how to
use the procedure and the content of the two sent parameters tcCode and
tnCount would bee very appreciated.

Thanks in advance
Christina


"Josh Assing" <xjoshx@jassing.com> skrev i meddelandet
news:9potk0hm5vh6uka2gp0mfhhoo4lildfss5@4ax.com...
> Why not use Mutex?
>
> FUNCTION Mutex
> LPARAMETERS tcCode, tnCount
> LOCAL lnHandle
>
> DECLARE INTEGER CreateMutex IN win32api INTEGER Security, INTEGER
> Owned,STRING MutexName
> DECLARE INTEGER GetLastError IN win32api
> DECLARE INTEGER SetLastError IN win32api INTEGER ErrorCode
> * DECLARE INTEGER ReleaseMutex IN WIN32API INTEGER nHandle
>
> lnHandle = CreateMutex(0, IIF(VARTYPE(tncoutn)#"N" OR
tnCount<=0,1,tnCount),
> tcCode)
>
> IF GetLastError() # 0
> SetLastError(0)
> lnHandle = -1
> ENDIF
>
> RETURN lnHandle > 0
> ENDFUNC
>
>
> On Mon, 20 Sep 2004 10:38:00 GMT, "Ch Löfberg" <ch.lofberg@telia.com>
wrote:
>
> >Hi all!
> >
> >I was told that one way to prevent an user to open more than one instance
of
> >an app is to try to FLOCK() a file which is allready locked by the first
> >instance.
> >
> >I created a dummy file tlbTmp.dbf with one field only for this purpose.
But
> >the second attempt to FLOCK() doesn´t return .F. as supposed. A file
> >allready locked can be locked again and again and FLOCK() returns .T.
> >everytime.
> >
> >What is the trick to have this solution to work as supposed?
> >
> >Best regards
> >Christina
> >
>
>
> ---
> Remove x's to send.



Re: One instance only - VFP8/SP1 by Ch

Ch
Mon Sep 20 15:14:29 CDT 2004

Hi Lee!
Thank you! I downloaded the FirstInstance.prg and connected it to my
project. Four rows
early in my startprg;

IF !FirstInstance()
WAIT 'The app is already running' WINDOW
QUIT
ENDIF

It results in two errormessages;
1 API library is not found
2 File mainhwnd.prg does not exist

After ignoring them it works as supposed with an exeption for the "bring to
front" feature which didn´t work.

What´s missing? How can I avoid the errors and how can I have the "bring to
front" feature to work.
Regards
Christina

"Lee Mitchell" <Leemi@online.microsoft.com> skrev i meddelandet
news:DV6zdlxnEHA.2932@cpmsftngxa06.phx.gbl...
> Hi Christina:
>
> Take a look at the FirstInstance.prg available from Universalthread.com.
Go
> to www.universalthread.com, click on the Download icon, and choose Visual
> FoxPro as the product. In the ID text box of the query page, search for
> "9497.
>
> I hope this helps.
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Sincerely,
> Microsoft FoxPro Technical Support
> Lee Mitchell
>
> *-- VFP9 Public Beta Now Available!! --*
> Download the VFP9 beta here: http://msdn.microsoft.com/vfoxpro/
>
> *-- VFP8 HAS ARRIVED!! --*
> Read about all the new features of VFP8 here:
> http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
> Purchase VFP8 here:
> http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518
>
> Keep an eye on the product lifecycle for Visual FoxPro here:
> http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
> - VFP5 Mainstream Support retired June 30th, 2003
> - VFP6 Mainstream Support retired Sept. 30th, 2003
>
> >Hi all!
>
> >I was told that one way to prevent an user to open more than one instance
> of
> >an app is to try to FLOCK() a file which is allready locked by the first
> >instance.
>
> >I created a dummy file tlbTmp.dbf with one field only for this purpose.
But
> >the second attempt to FLOCK() doesn´t return .F. as supposed. A file
> >allready locked can be locked again and again and FLOCK() returns .T.
> >everytime.
>
> >What is the trick to have this solution to work as supposed?
>
> >Best regards
> >Christina
>




Re: One instance only - VFP8/SP1 by Josh

Josh
Mon Sep 20 21:56:55 CDT 2004

in your program:

if Mutex("MyProgram")
* ok to continue
else
* another version is arleady running
endif




On Mon, 20 Sep 2004 16:26:33 GMT, "Ch Löfberg" <ch.lofberg@telia.com> wrote:

>Josh - I´m new to this, and it looks exciting. A short explanation how to
>use the procedure and the content of the two sent parameters tcCode and
>tnCount would bee very appreciated.
>
>Thanks in advance
>Christina
>
>
>"Josh Assing" <xjoshx@jassing.com> skrev i meddelandet
>news:9potk0hm5vh6uka2gp0mfhhoo4lildfss5@4ax.com...
>> Why not use Mutex?
>>
>> FUNCTION Mutex
>> LPARAMETERS tcCode, tnCount
>> LOCAL lnHandle
>>
>> DECLARE INTEGER CreateMutex IN win32api INTEGER Security, INTEGER
>> Owned,STRING MutexName
>> DECLARE INTEGER GetLastError IN win32api
>> DECLARE INTEGER SetLastError IN win32api INTEGER ErrorCode
>> * DECLARE INTEGER ReleaseMutex IN WIN32API INTEGER nHandle
>>
>> lnHandle = CreateMutex(0, IIF(VARTYPE(tncoutn)#"N" OR
>tnCount<=0,1,tnCount),
>> tcCode)
>>
>> IF GetLastError() # 0
>> SetLastError(0)
>> lnHandle = -1
>> ENDIF
>>
>> RETURN lnHandle > 0
>> ENDFUNC
>>
>>
>> On Mon, 20 Sep 2004 10:38:00 GMT, "Ch Löfberg" <ch.lofberg@telia.com>
>wrote:
>>
>> >Hi all!
>> >
>> >I was told that one way to prevent an user to open more than one instance
>of
>> >an app is to try to FLOCK() a file which is allready locked by the first
>> >instance.
>> >
>> >I created a dummy file tlbTmp.dbf with one field only for this purpose.
>But
>> >the second attempt to FLOCK() doesn´t return .F. as supposed. A file
>> >allready locked can be locked again and again and FLOCK() returns .T.
>> >everytime.
>> >
>> >What is the trick to have this solution to work as supposed?
>> >
>> >Best regards
>> >Christina
>> >
>>
>>
>> ---
>> Remove x's to send.
>


---
Remove x's to send.

Re: One instance only - VFP8/SP1 by Ch

Ch
Mon Sep 20 23:03:43 CDT 2004

I found the reason for the error "API library is not found". It disappeared
after foxtools was made available. It still should be nice to have
"bring to front" feature working.

Some ideas?

Christina


"Lee Mitchell" <Leemi@online.microsoft.com> skrev i meddelandet
news:DV6zdlxnEHA.2932@cpmsftngxa06.phx.gbl...
> Hi Christina:
>
> Take a look at the FirstInstance.prg available from Universalthread.com.
Go
> to www.universalthread.com, click on the Download icon, and choose Visual
> FoxPro as the product. In the ID text box of the query page, search for
> "9497.
>
> I hope this helps.
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Sincerely,
> Microsoft FoxPro Technical Support
> Lee Mitchell
>
> *-- VFP9 Public Beta Now Available!! --*
> Download the VFP9 beta here: http://msdn.microsoft.com/vfoxpro/
>
> *-- VFP8 HAS ARRIVED!! --*
> Read about all the new features of VFP8 here:
> http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
> Purchase VFP8 here:
> http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518
>
> Keep an eye on the product lifecycle for Visual FoxPro here:
> http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
> - VFP5 Mainstream Support retired June 30th, 2003
> - VFP6 Mainstream Support retired Sept. 30th, 2003
>
> >Hi all!
>
> >I was told that one way to prevent an user to open more than one instance
> of
> >an app is to try to FLOCK() a file which is allready locked by the first
> >instance.
>
> >I created a dummy file tlbTmp.dbf with one field only for this purpose.
But
> >the second attempt to FLOCK() doesn´t return .F. as supposed. A file
> >allready locked can be locked again and again and FLOCK() returns .T.
> >everytime.
>
> >What is the trick to have this solution to work as supposed?
>
> >Best regards
> >Christina
>