
TaskFirst and TaskNext functions - anyone get them to work?
Has anyone successfully implemented the TaskFirst and TaskNext functions
as detailed in one of the 99 VB4 tips found at www.windx.com.
You're supposed to be able to determine when an app is complete
but when I try out the code I get a run-time error '48'.
My test code is:
Function IsInst(hInst As Long) As Boolean
Dim taskstruct As TaskEntry
Dim retc As Boolean
IsInst = False
taskstruct.dwSize = Len(taskstruct)
retc = TaskFirst(taskstruct)
Do While retc
If taskstruct.hInst = hInst Then
' note: the task handle is: taskstruct.hTask
IsInst = True
Exit Function
End If
retc = TaskNext(taskstruct)
Loop
End Function
'Declarations section:
Private Type TaskEntry
dwSize As Long
HTASK As Long
hTaskParent As Long
hInst As Long
hModule As Long
wSS As Long
wSP As Long
wStackTop As Long
wStackMinimum As Long
wStackBottom As Long
wcEvents As Long
hQueue As Long
' szModule(MAX_MODULE_NAME + 1) As String
wPSPOffset As Long
hNext As Long
End Type
Private Declare Function TaskNext Lib "toolhelp.dll" Alias "TASKNEXT"
_(taskstruct As TaskEntry) As Long
Private Declare Function TaskFirst Lib "toolhelp.dll" Alias "TASKFIRST"
_(taskstruct As TaskEntry) As Long
Private Sub Command1_Click()
Dim hInst As Long
hInst = Shell("notepad.exe")
Do While IsInst(hInst)
DoEvents
Loop
MsgBox "Hello"
End Sub
Thanks for any help,
Dan Stoelting