Zophar's Message Domain

Go Back   Zophar's Message Domain > General Chat > Talk of the Town

Reply
 
Thread Tools Display Modes
Old 10-30-2004, 08:35 AM   #1
JCE3000GT
Senior Member
 
JCE3000GT's Avatar
 
Join Date: Sep 2001
Location: Little Elm, TX
Posts: 5,167
Default VB6 question

I'm in the process of coding an app for a specific use...but I can't seem to find any info on how to detect a program that's "not responding" then to close and reopen that program. Anyone know a good set of API calls (or provide a module for me) that can accomplish this? As this is the main goal of the program is to detect the crash, end the task/terminate the program, and reopen it (this is the easy step I know already). Any help is greatly appreciated.

<P ID="signature"></P>
JCE3000GT is offline   Reply With Quote
Old 10-30-2004, 09:15 AM   #2
SirDaShadow
Senior Member
 
Join Date: Aug 2001
Posts: 1,291
Default Re: VB6 question


> step I know already). Any help is greatly appreciated.
this is not VB, this is in rapidq, but it may give you an idea as the api is called the same way
>
$INCLUDE "RAPIDQ.INC"


'constantes
CONST LVM_FIRST = &H1000
CONST LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
CONST LVEX_GRIDLINES = 1
CONST LVEX_SUBITEMIMAGES = 2
CONST LVEX_CHECKBOXES = 4
CONST LVEX_TRACKSELECT = 8
CONST LVEX_HEADERDRAGDROP = 16
CONST LVEX_FULLROWSELECT = 32
CONST LVEX_ONECLICKACTIVATE = 64
CONST LVEX_TWOCLICKACTIVATE = 128



Const TH32CS_SNAPPROCESS As Long = 2&
Type PROCESSENTRY32
dwSize As DWORD
cntUsage As DWORD
th32ProcessID As DWORD
th32DefaultHeapID As DWORD
th32ModuleID As DWORD
cntThreads As DWORD
th32ParentProcessID As DWORD
pcPriClassBase As Long
dwFlags As DWORD
szexeFile As string*255
End Type


'APIs
Declare Function CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" _
(ByVal hSnapshot As Long, uProcess As long) As Long

Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" _
(ByVal hSnapshot As Long, uProcess As long) As Long

Declare Sub CloseHandle Lib "kernel32" alias "CloseHandle" (ByVal hPass As Long)



' Copy and paste into your program
DECLARE SUB list (Sender AS QBUTTON)

CREATE Form AS QFORM
Caption = "List des process en cours"
Width =580
Height = 550
Center
CREATE Button1 AS QBUTTON
Caption = "List"
width=200
Left = 0
Top = 50
OnClick = list
END CREATE
CREATE TheList AS QLISTview
Left = 0
Top = 80
Width = 570
Height = 425
TabOrder = 1
ViewStyle = vsReport

AddColumns "PID","Nbr thread","priorité","Nom"
Column(0).Width = 80
Column(1).Width = 80
Column(2).Width = 50

Column(3).Width = 400

HotTrack =true

END CREATE
CREATE edit AS Qedit
Left =0
Top = 0
Width = 100
Height = 20
END CREATE

END CREATE

'Insert your initialization code here
SendMessage(ListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, _
LVEX_CHECKBOXES OR LVEX_FULLROWSELECT OR LVEX_GRIDLINES)

Form.ShowModal

'--------- Subroutines ---------

SUB list (Sender AS QBUTTON)
dim x as integer

Dim hSnapshot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
dim pointeur as long
dim pointeur1 as long
TheList.Clear
x=0
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapshot = 0 Then
Exit Sub
End If
uProcess.dwSize =sizeof(uProcess)+255
r = ProcessFirst(hSnapshot,uProcess)
While r
'process ID
TheList.AddItems hex$(uProcess.th32ProcessID)
'nbr de thread
TheList.AddSubItem x, str$(uProcess.cntThreads)
'priorité
TheList.AddSubItem x, str$(uProcess.pcPriClassBase)
'chemin
TheList.AddSubItem x, uProcess.szexeFile
x=x+1
r = ProcessNext(hSnapshot, uProcess)
wend
Call CloseHandle(hSnapshot)

edit.text=str$(TheList.itemcount)

END SUB

<P ID="signature"></P>
SirDaShadow is offline   Reply With Quote
Old 10-30-2004, 11:28 AM   #3
Gavin_86
Senior Member
 
Join Date: Aug 2002
Posts: 1,082
Default Re: VB6 question

adding onto what SirDaShadow wrote, you can use this:

<pre>Declare Function GetLastError Lib "kernel32" Alias "GetLastError" () As Long</pre>

to retrieve the last error, but you may want to note that this is on a per Thread basis. Each thread has it's own last error report, instead of one catch all last error.

<P ID="signature"><center>I'm just a Paranoid Android watching through my superb crystal viewing glass

.::http://gavin.panicus.orgGavin.Panicus.org</a> ::.
</center></P>
Gavin_86 is offline   Reply With Quote
Old 10-30-2004, 12:34 PM   #4
JCE3000GT
Senior Member
 
JCE3000GT's Avatar
 
Join Date: Sep 2001
Location: Little Elm, TX
Posts: 5,167
Default Re: VB6 question

> Declare Function GetLastError Lib "kernel32" Alias
> "GetLastError" () As Long
>
> to retrieve the last error, but you may want to note that
> this is on a per Thread basis. Each thread has it's own last
> error report, instead of one catch all last error.

Got any examples on how to tell if the application in question isn't responding using this function?

<P ID="signature"></P>
JCE3000GT is offline   Reply With Quote
Old 10-30-2004, 01:07 PM   #5
SirDaShadow
Senior Member
 
Join Date: Aug 2001
Posts: 1,291
Default Re: VB6 question

> Got any examples on how to tell if the application in
> question isn't responding using this function?
Use SendMessageTimeout to send a message to the window. If the message times out after, say, 10 seconds, you can assume the applcation is not responding (the task manager assumes this after 5 seconds).

assume h is the window handle:

if SendMessageTimeout(H, WM_NULL, 0, 0, SMTO_NORMAL, 100, Res) <> 0 then
showmessage("'Responding")
else
showmessage("'Not Responding")
end if


edit: Send MessageTimeout's declaration


<P ID="signature"></P><P ID="edit"><FONT class="small">Edited by SirDaShadow on 10/30/04 09:09 AM.</FONT></P>
SirDaShadow is offline   Reply With Quote
Old 10-31-2004, 03:17 PM   #6
JCE3000GT
Senior Member
 
JCE3000GT's Avatar
 
Join Date: Sep 2001
Location: Little Elm, TX
Posts: 5,167
Default Re: VB6 question

Hmm interesting. I'll give it a whirl. Thanks.

<P ID="signature"></P>
JCE3000GT is offline   Reply With Quote
Old 11-01-2004, 06:16 PM   #7
cipher
Senior Member
 
Join Date: May 2001
Posts: 1,034
Default Re: VB6 question

Use 'SendMessageTimeout' with SMTO_ABORTIFHUNG and SMTO_BLOCK as flags. It'll return 0 is the window is not responding. You can use GetWindowThreadProcessId to get the process ID and use TerminateProcess to kill the process. GetModuleFileNameEx should let you get the filename of the application so you can restart it.

<P ID="signature">-----
ciphz0r</P>
cipher is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:56 AM.

Contact Us - Zophar's Domain - Archive - Top

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.