Why exe closes for no reason?
Okay, I have this project, and for some reason if I build the exe, it works fine for me, and it works fine for some people, but for some people, it will open fine, but hitting this button or hitting this menu menu to open another window, it just closes... There is no error messages, it just closes?
The only extra ocx file I'M using is the richtxt32.ocx and then a few user controls.
Re: Why exe closes for no reason?
How are you distrbuting the program? Are you just sending them the exe and/or a few files? If so you need to instead create a set of installion files via the P&D Wizard, Inno, or similar and send the output to them.
Re: Why exe closes for no reason?
Well, I know the person has the runtime files, and everything that they need, it's just it works for some people, and for some people it doesn't. I really don't know how to explain it.
Re: Why exe closes for no reason?
Also if you dont have any error handling in your app then it may not generate an error message.
Re: Why exe closes for no reason?
Try what I said for one person and see what happens.
Re: Why exe closes for no reason?
I had a problem like that once and it had to do with the order a form load was loading items and running subs. Why it only happened once in a while i still do not know. The hardest part is getting a user to inform you what they were doing when it happened. Luckily my customer was a little computer savy and i ended up giving him a exe with error line numbers in every sub on the form causing the problem. I would at least give the users with a problem a exe with line numbers that write to a log file. I spent a lot of time on this problem and now have went so far as to write error code that automatically emails me the subs name with the error description and line number thru a online jmail and writes to a log file. Thing is now i never get any errors. If you could get a user to tell you what they were doing at least you would have a place to start.
Re: Why exe closes for no reason?
Well, it happens when a user just clicks a button. And all that button is doing is calling one single sub routine...
I don't see any problems with it.
Re: Why exe closes for no reason?
Quote:
Originally Posted by JoshHilton
Well, it happens when a user just clicks a button. And all that button is doing is calling one single sub routine...
I don't see any problems with it.
There are other buttons that run subs with no problem ? Post the sub maybe there is something you are missing
Re: Why exe closes for no reason?
There are other buttons and they work fine, but this sub calls about 5 others... then adds the item they find to the list on the main form.
The button calls ScanRooms()
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Function ScanRooms()
'Find Existing rooms first
Dim tmplist As String
For a = 0 To MainForm.channellist.ListCount - 1
If MainForm.channellist.ItemSelected(a) = True Then
tmplist = tmplist & MainForm.channellist.ItemText(a)
End If
Next a
'Clear the list
MainForm.channellist.Clear
DoEvents
'Scan WinMX
Call ScanWinMXWindow
Call ScanMetisWindow
Call ScanRoboWindow
Call ScanOukaWindow
Call ScanRabbitWindow
'Call ScanWinMXPeerWindow
'Apply Previous Selections
Dim tmpsplit() As String
tmpsplit = Split(tmplist, vbCrLf)
For a = 0 To UBound(tmpsplit)
For B = 0 To MainForm.channellist.ListCount - 1
If MainForm.channellist.ItemText(B) = tmpsplit(a) Then
MainForm.channellist.ItemSelected(B) = True
End If
Next B
Next a
End Function
Sub ScanWinMXWindow()
Dim Top As Long
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Dim Title As String
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
Title = Left(Title, Ret)
If (Ret > 0 And InStr(Title, "WinMX v3.")) Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetWindowText(Inner, Title, 100)
If (Ret > 0 And InStr(Title, "on WinMX Peer Network")) Then
Title = Left(Title, Ret)
MainForm.channellist.AddItem Left(Title, Len(Title) - 22)
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanMetisWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(300)
Ret = GetWindowText(Top, Title, 300)
If InStr(Title, "Metis") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetWindowText(Inner2, Title, 100)
If InStr(Title, "(") Then
Dim ChannelName As String
ChannelName = Split(Title, " (")(0)
'MsgBox ChannelName 'CHANNEL NAME HERE
MainForm.channellist.AddItem (ChannelName)
End If
Inner2 = FindWindowEx(Inner, Inner2, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanRoboWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(300)
Ret = GetWindowText(Top, Title, 300)
If InStr(Title, "Robo") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetWindowText(Inner2, Title, 100)
If InStr(Title, "(") Then
Dim ChannelName As String
ChannelName = Split(Title, " (")(0)
'MsgBox ChannelName 'CHANNEL NAME HERE
MainForm.channellist.AddItem (ChannelName)
End If
Inner2 = FindWindowEx(Inner, Inner2, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanOukaWindow()
Dim Top As Long
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Dim Title As String
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
Title = Left(Title, Ret)
' If (Ret > 0 And InStr(title, "WinMX v3.")) Then
If (Ret > 0 And InStr(Title, "Ouka Chat Client")) Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim InnerChat As Long
InnerChat = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (InnerChat <> 0)
Title = Space(100)
Ret = GetClassName(InnerChat, Title, 100)
If InStr(Title, "MDICHAT") Then
Dim ChannelName As String * 100
Ret = GetWindowText(InnerChat, ChannelName, 100)
MainForm.channellist.AddItem (ChannelName)
End If
InnerChat = FindWindowEx(Inner, InnerChat, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
'MsgBox Top
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanRabbitWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
If InStr(Title, "Rabbit v1.3") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, "WPNCLIENT", vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetClassName(Inner2, Title, 100)
'Found Channel Name here
Dim ChannelName As String * 100
Ret = GetWindowText(Inner2, ChannelName, 100)
MainForm.channellist.AddItem (ChannelName)
Inner2 = FindWindowEx(Inner, Inner2, "WPNCLIENT", vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Re: Why exe closes for no reason?
Quote:
Originally Posted by JoshHilton
There are other buttons and they work fine, but this sub calls about 5 others... then adds the item they find to the list on the main form.
The button calls ScanRooms()
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Function ScanRooms()
'Find Existing rooms first
Dim tmplist As String
For a = 0 To MainForm.channellist.ListCount - 1
If MainForm.channellist.ItemSelected(a) = True Then
tmplist = tmplist & MainForm.channellist.ItemText(a)
End If
Next a
'Clear the list
MainForm.channellist.Clear
DoEvents
'Scan WinMX
Call ScanWinMXWindow
Call ScanMetisWindow
Call ScanRoboWindow
Call ScanOukaWindow
Call ScanRabbitWindow
'Call ScanWinMXPeerWindow
'Apply Previous Selections
Dim tmpsplit() As String
tmpsplit = Split(tmplist, vbCrLf)
For a = 0 To UBound(tmpsplit)
For B = 0 To MainForm.channellist.ListCount - 1
If MainForm.channellist.ItemText(B) = tmpsplit(a) Then
MainForm.channellist.ItemSelected(B) = True
End If
Next B
Next a
End Function
Sub ScanWinMXWindow()
Dim Top As Long
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Dim Title As String
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
Title = Left(Title, Ret)
If (Ret > 0 And InStr(Title, "WinMX v3.")) Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetWindowText(Inner, Title, 100)
If (Ret > 0 And InStr(Title, "on WinMX Peer Network")) Then
Title = Left(Title, Ret)
MainForm.channellist.AddItem Left(Title, Len(Title) - 22)
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanMetisWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(300)
Ret = GetWindowText(Top, Title, 300)
If InStr(Title, "Metis") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetWindowText(Inner2, Title, 100)
If InStr(Title, "(") Then
Dim ChannelName As String
ChannelName = Split(Title, " (")(0)
'MsgBox ChannelName 'CHANNEL NAME HERE
MainForm.channellist.AddItem (ChannelName)
End If
Inner2 = FindWindowEx(Inner, Inner2, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanRoboWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(300)
Ret = GetWindowText(Top, Title, 300)
If InStr(Title, "Robo") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetWindowText(Inner2, Title, 100)
If InStr(Title, "(") Then
Dim ChannelName As String
ChannelName = Split(Title, " (")(0)
'MsgBox ChannelName 'CHANNEL NAME HERE
MainForm.channellist.AddItem (ChannelName)
End If
Inner2 = FindWindowEx(Inner, Inner2, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanOukaWindow()
Dim Top As Long
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Dim Title As String
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
Title = Left(Title, Ret)
' If (Ret > 0 And InStr(title, "WinMX v3.")) Then
If (Ret > 0 And InStr(Title, "Ouka Chat Client")) Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim InnerChat As Long
InnerChat = FindWindowEx(Inner, 0, vbNullString, vbNullString)
While (InnerChat <> 0)
Title = Space(100)
Ret = GetClassName(InnerChat, Title, 100)
If InStr(Title, "MDICHAT") Then
Dim ChannelName As String * 100
Ret = GetWindowText(InnerChat, ChannelName, 100)
MainForm.channellist.AddItem (ChannelName)
End If
InnerChat = FindWindowEx(Inner, InnerChat, vbNullString, vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
'MsgBox Top
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
Sub ScanRabbitWindow()
Dim Top As Long
Dim Ret As Long
Dim Title As String
Top = FindWindowEx(0, 0, vbNullString, vbNullString)
While (Top <> 0)
Title = Space(100)
Ret = GetWindowText(Top, Title, 100)
If InStr(Title, "Rabbit v1.3") Then
Dim Inner As Long
Inner = FindWindowEx(Top, 0, vbNullString, vbNullString)
While (Inner <> 0)
Title = Space(100)
Ret = GetClassName(Inner, Title, 100)
If InStr(Title, "MDIClient") Then
Dim Inner2 As Long
Inner2 = FindWindowEx(Inner, 0, "WPNCLIENT", vbNullString)
While (Inner2 <> 0)
Title = Space(100)
Ret = GetClassName(Inner2, Title, 100)
'Found Channel Name here
Dim ChannelName As String * 100
Ret = GetWindowText(Inner2, ChannelName, 100)
MainForm.channellist.AddItem (ChannelName)
Inner2 = FindWindowEx(Inner, Inner2, "WPNCLIENT", vbNullString)
Wend
End If
Inner = FindWindowEx(Top, Inner, vbNullString, vbNullString)
Wend
End If
Top = FindWindowEx(0, Top, vbNullString, vbNullString)
Wend
End Sub
I would not call that one single sub routine. You need to write error handlers
on all those subroutines. With no error handlers it could be anywhere
Re: Why exe closes for no reason?
Well, wouldn't any errors just trigger a runtime error/other that you always get...
Re: Why exe closes for no reason?
Quote:
Originally Posted by JoshHilton
Well, wouldn't any errors just trigger a runtime error/other that you always get...
No.
And even if they did, how are you going to know what error they trigger? You need to write code that traps errors and tells you what they are. I would even go so far as to program in a debug mode. Plus you should set your compile options to include line numbers, etc.
As you are using api calls though i am willing to bet one of them is the culprit. You are reading the handle to a window and it's not finding the window then posting a message to a non existing window or something like that.
Probably the simplest thing you can do for now is to make a small change to your code like this:
Code:
open "debug.txt" for output as #1
call ScanWinMXWindow: print #1, "a"
Call ScanMetisWindow: print #1, "b"
Call ScanRoboWindow: print #1, "c"
Call ScanOukaWindow: print #1, "d"
Call ScanRabbitWindow: print #1, "e"
Call ScanWinMXPeerWindow: print #1,"f"
close #1
this will make a debug file that is telling you which sub is crashing the program. For example if the file says a b c d then you know scanrabbitwindow did not work.
Re: Why exe closes for no reason?
should open and close the output file as append file, for each time you print, if the program crashes the file will not be closed correctly
proper error handling is essential
Re: Why exe closes for no reason?
i opened it as output so it would be overwritten upon open. it "should" close the file handles when it crashes.