[VW7.4] Windows Intergration: Double-click on documents, single-instance runtime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[VW7.4] Windows Intergration: Double-click on documents, single-instance runtime

Andre Schnoor
Hi all,

I'm having a hard time making my VW application behave (almost) like a
normal Windows program. Are there simple solutions to these basic problems:

1. Double-clicking on a document (extension registered with windows)
always opens a new executable instance. I'd like to have the already
running instance open the file instead. Where can I hook this in? I
guess the new runtime startup system has plenty of possibilities to do that.

2. How can I ensure that only a single instance is running? I believe
locking a file or a similar "industry standard" hack is not a safe
solution ;-)

Any hint is appreciated.
Andre

Reply | Threaded
Open this post in threaded view
|

RE: [VW7.4] Windows Intergration: Double-click on documents, single-instance runtime

Steven Kelly
From: [hidden email] [mailto:[hidden email]]
> 1. Double-clicking on a document (extension registered with windows)
> always opens a new executable instance. I'd like to have the already
> running instance open the file instead. Where can I hook this in?

Try looking in contributed/WindowsDDE/. I don't know of anything else
that offers this for VW.

> 2. How can I ensure that only a single instance is running? I believe
> locking a file or a similar "industry standard" hack is not a safe
> solution ;-)

Try a web search for mutex AND single. Create a uniquely named mutex
using the CreateMutex DLL call. CreateMutex will succeed even if the
mutex already exists, but the function will return ERROR_ALREADY_EXISTS.
This indicates that another instance of your application exists, because
it created the mutex first.

Windows' CreateMutex is defined in kernel32.dll (you probably want
CreateMutexA) and declared in Winbase.h.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc
/base/createmutex.asp

Looks like someone tried this in Dolphin:
http://www.talkaboutprogramming.com/group/comp.lang.smalltalk.dolphin/me
ssages/13258.html
(links to all posts in this thread are at the bottom of that page)

HTH,
Steve

Reply | Threaded
Open this post in threaded view
|

Re: [VW7.4] Windows Intergration: Double-click on documents, single-instance runtime

Andre Schnoor

Steven Kelly wrote:
From: [hidden email] [[hidden email]]
  
1. Double-clicking on a document (extension registered with windows)
always opens a new executable instance. I'd like to have the already
running instance open the file instead. Where can I hook this in? 
    

Try looking in contributed/WindowsDDE/. I don't know of anything else
that offers this for VW.

  
2. How can I ensure that only a single instance is running? I believe
locking a file or a similar "industry standard" hack is not a safe
solution ;-)
    

Try a web search for mutex AND single. Create a uniquely named mutex
using the CreateMutex DLL call. CreateMutex will succeed even if the
mutex already exists, but the function will return ERROR_ALREADY_EXISTS.
This indicates that another instance of your application exists, because
it created the mutex first. 
  


That works fine, thanks Steve.

Microsoft doesn't seem to trust it's API though:

"If you are using a named mutex to limit your application to a single instance, a malicious user can create this mutex before you do and prevent your application from starting. To prevent this situation, create a randomly named mutex and store the name so that it can only be obtained by an authorized user. Alternatively, you can use a file for this purpose. To limit your application to one instance per user, create a locked file in the user's profile directory."

Can't believe it.

Andre

Reply | Threaded
Open this post in threaded view
|

Re: [VW7.4] Windows Intergration: Double-click on documents, single-instance runtime

Mark Pirogovsky-3
Andre,

I am using successfully the DDE from the contributed.  E-mail me if you
want the gory details of it.

Also there is a way to enable your application for the "drag and  drop"
so the user can simply drag files from the Explorer onto your
application window - make it look even more as other windows apps.

One of the problem I have encountered with the DDE that I do have to
suppress the SPlash screen to be able fully utilize that technique did
complain about it numerous times to no avail).

Also there is a way to enable your application for the "drag and  drop"
so the user can simply drag files from the Explorer onto your
application window...

However it does not prevent the user from being able to open your
application multiple times from the shortcut or command prompt.

If you feel using mutex undesirable ( I feel the same way BTW) then you
can  make sure that only one instance of your application is running you
in couple of ways which give your appellation total control of the
situation:

1. if you use DDE.  Your app will start the DDE server at the startup
and advertise the named application as available to the DDE
conversation.  So every time you start check if somebody already running
  this and quit with some message.

2. On the startup you can check the list of the running processes and if
you see the process of the same name and file location already running
you can quit.

Hoe this helps,

--Mark Pirogovsky

Andre Schnoor wrote:

>
> Steven Kelly wrote:
>
>>From: [hidden email] [mailto:[hidden email]]
>>  
>>
>>>1. Double-clicking on a document (extension registered with windows)
>>>always opens a new executable instance. I'd like to have the already
>>>running instance open the file instead. Where can I hook this in?
>>>    
>>>
>>
>>Try looking in contributed/WindowsDDE/. I don't know of anything else
>>that offers this for VW.
>>
>>  
>>
>>>2. How can I ensure that only a single instance is running? I believe
>>>locking a file or a similar "industry standard" hack is not a safe
>>>solution ;-)
>>>    
>>>
>>
>>Try a web search for mutex AND single. Create a uniquely named mutex
>>using the CreateMutex DLL call. CreateMutex will succeed even if the
>>mutex already exists, but the function will return ERROR_ALREADY_EXISTS.
>>This indicates that another instance of your application exists, because
>>it created the mutex first.
>>  
>>
>
>
> That works fine, thanks Steve.
>
> Microsoft doesn't seem to trust it's API though:
>
> "If you are using a named mutex to limit your application to a single
> instance, a malicious user can create this mutex before you do and
> prevent your application from starting. To prevent this situation,
> create a randomly named mutex and store the name so that it can only be
> obtained by an authorized user. Alternatively, you can use a file for
> this purpose. To limit your application to one instance per user, create
> a locked file in the user's profile directory."
>
> Can't believe it.
>
> Andre
>