Sinna
2006-08-02 11:42:54 UTC
Hi,
Based on the code found at http://www.thescarms.com/VBasic/wait.asp, I
use WaitForSingleObject to get notification if a launched application
is closed. That piece of code works like a charm.
Now I want to mimick the Windows Explorer so the corresponding
application is launched for a given file (extension). To accomplish
SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_DDEWAIT Or _
SEE_MASK_DOENVSUBST Or SEE_MASK_FLAG_NO_UI Or _
SEE_MASK_UNICODE Or SEE_MASK_WAITFORINPUTIDLE
The documentation from the MSDN Library states that after a
successfull launch the hProcess parameter of the SHELLEXECUTEINFO
structure contains the handle to the process.
However, when I use the handle returned in the SHELLEXECUTEINFO
structure for the WaitForSingleObject call, the function returns
immediately with WAIT_OBJECT_0, regardless whether the application is
still running or not.
Private Declare Function WaitForSingleObject Lib "kernel32.dll" ( _
ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Const INFINITE As Long = -1& ' Infinite interval
Private Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
Private Const SEE_MASK_FLAG_DDEWAIT As Long = &H100
Private Const SEE_MASK_DOENVSUBST As Long = &H200
Private Const SEE_MASK_FLAG_NO_UI As Long = &H400
Private Const SEE_MASK_UNICODE As Long = &H4000
Private Const SEE_MASK_WAITFORINPUTIDLE As Long = &H2000000
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hWnd As Long
lpVerb As Long
lpFile As Long
lpParameters As Long
lpDirectory As Long
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As Long
hKeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Private Declare Function ShellExecuteEx Lib "shell32.dll" _
Alias "ShellExecuteExW" ( _
ByRef lpExecInfo As SHELLEXECUTEINFO) As Long
Note I use the Wide variant of the ShellExecuteEx call. This is a
requirement since I have to support unicode filenames.
TIA,
Sinna
Update!Based on the code found at http://www.thescarms.com/VBasic/wait.asp, I
use WaitForSingleObject to get notification if a launched application
is closed. That piece of code works like a charm.
Now I want to mimick the Windows Explorer so the corresponding
application is launched for a given file (extension). To accomplish
SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_DDEWAIT Or _
SEE_MASK_DOENVSUBST Or SEE_MASK_FLAG_NO_UI Or _
SEE_MASK_UNICODE Or SEE_MASK_WAITFORINPUTIDLE
The documentation from the MSDN Library states that after a
successfull launch the hProcess parameter of the SHELLEXECUTEINFO
structure contains the handle to the process.
However, when I use the handle returned in the SHELLEXECUTEINFO
structure for the WaitForSingleObject call, the function returns
immediately with WAIT_OBJECT_0, regardless whether the application is
still running or not.
Private Declare Function WaitForSingleObject Lib "kernel32.dll" ( _
ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Const INFINITE As Long = -1& ' Infinite interval
Private Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
Private Const SEE_MASK_FLAG_DDEWAIT As Long = &H100
Private Const SEE_MASK_DOENVSUBST As Long = &H200
Private Const SEE_MASK_FLAG_NO_UI As Long = &H400
Private Const SEE_MASK_UNICODE As Long = &H4000
Private Const SEE_MASK_WAITFORINPUTIDLE As Long = &H2000000
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hWnd As Long
lpVerb As Long
lpFile As Long
lpParameters As Long
lpDirectory As Long
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As Long
hKeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Private Declare Function ShellExecuteEx Lib "shell32.dll" _
Alias "ShellExecuteExW" ( _
ByRef lpExecInfo As SHELLEXECUTEINFO) As Long
Note I use the Wide variant of the ShellExecuteEx call. This is a
requirement since I have to support unicode filenames.
TIA,
Sinna
It seems the issue only exists on WinXP systems. I've executed the code
on Win2K and Win2K3 without problems.
Can somebody confirm this?
Sinna
After some puzzling I found out that the function only fails in very
specific circumstances: when launching the ShellExecuteEx call with
lpVerb = "edit" and lpFile = StrPtr("foo.xml") the WaitForSingleObject
call returns immediately. In my case Notepad is launched.
If I launch the ShellExecuteEx call with another file (e.g. foo.txt)
everything works as expected.
Sinna