Mars base one Username: Jim Davis Password: yCrm33
Posts
1,284
Re: App closing sequence
Here is an example project that will show you simplified the problem, im facing with. Theres dont need to put these controls to a usercontrol-container, its just enough to place them to an mdi child, to get the crash.
The code will create 10 clones of form1, each form will contain 10 instances of ccXpButton.
I had to modify the usercontrol, to avoid the Client Site not available error, i included the InDevelopment "hack". I think this is not the reason of the crash, because the compiled code is also crashing. But if you feel like, you can double check it of course. Its better to close the child forms one by one (even better to use the ctrl+f4 for mass closing them). The crash will occur immediately, but in rare cases it just doesnt. In case you didnt got any crash, just restart the app, do the mass-closing, then the crash will occur i am sure.
I know, that bugfixing someone else's code is stinks, i dont ask you to do. What i only to ask you, about experiences how did you avoid crashes, using subclassed usercontrols.
12/22/2004 11:23:03 PM: James...
Hi Chris i tried to email but got returned email form the email supplied. I think there is a problem when you run it in a MDI environment as a complied exe. Have not been able to pinpoint it but it will cause a random crash when the form is unloading. Only happens when the control and project are comlpied.
12/29/2004 4:14:14 PM: Chris Cochran
James,
The problem you mentioned above is related to the mouseleave trapping. I am working the issue.
Not sure why you are having problem with the e-mail link, it works for all others.
Chris
Ok, it seems like the control have the issue, ive just missed this conversation
Last edited by Jim Davis; Nov 30th, 2008 at 03:58 AM.
I've seen this problem before. The uc is subclassing the parent. When multiple uc's subclass the same parent, the crashes are common. What is happening is that the uc's are subclassing in order of loading: uc1, uc2, uc3, etc. But when unloading, they do not unload in reverse order to restore the subclassing stack, they unload in first loaded, first unloaded order. Let's look at it this way
Code:
' When UCs are loaded
UC1 subclasses: oldWndProc is Original
UC2 subclasses: oldWndProc is that in UC1
UC3 subclasses: oldWndProc is that in UC2
' When UC's are unloaded
UC1 unloads & resets subclass procedure to Original procedure
UC2 unloads & resets subclass procedure to that in UC1
>> crash. The procedure in UC1 is no longer in memory, it was unloaded
You can verify this yourself with a simple test project:
Code:
1. Add new form
2. Add new usercontrol (not yours, just a blank uc)
3. In UC, add this to Initialize event: Debug.Print "Loaded "; ObjPtr(Me)
4. In UC, add this to Terminate event: Debug.Print "Unloaded "; ObjPtr(Me)
5. Add 3 UCs to your form
6. Close your form in design view, Open Debug window (CTRL+G)
7. Clear any entries in it. Run test project. Close test project normally (X)
8. Open debug window & look at order loaded, unloaded.
I have tweaked Paul Caton's subclassing to avoid this issue. Basically, I've added a delay timer in the ASM thunk. The thunks prevent unloading the window procedure until a short timer expires, then unloads it. This works really well for UCs. You can find the modified thunks on PSC (as of this reply, PSC appears down for maintenance, so the link was obtained from googling & hopefully it is the correct one). http://www.planetsourcecode.com/vb/s...68737&lngWId=1
Edited: This becomes even more crash prone when you have other UCs (3rd party) that subclass the parent also. The order of subclassing/unsubclassing is not in your control. And if those others use similar subclassing techniques as does your uc, what a mess! Which is the reason I don't write UCs to subclass any container/outside object, unless subclassing starts in a sub/function and terminates subclassing before the sub/function terminates.
Last edited by LaVolpe; Nov 30th, 2008 at 10:45 AM.
Insomnia is just a byproduct of, "It can't be done"
Quite frankly, I had a similar, if not the same problem.
I created a SubClassed UserControl and realised if only 1 instance was placed on a form it worked fine, without any crashes. But if multiple instances of the control were placed, then there was always a crash.
After tracking down, I spotted the problem and seem to have fixed it.
I always start off with a template of Paul Caton, which has a ready made Subclassed template of a UserControl.
In the SubClassed UserControl, you should probably have a Subclass_StopAll function. Find it and change it to this:
vb Code:
'Stop all subclassing
Private Sub Subclass_StopAll()
Dim i As Long
Dim getControlNo As Single
Dim wasHere As Boolean
i = UBound(sc_aSubData()) 'Get the upper bound of the subclass data array
Do While i >= 0 'Iterate through each element
With sc_aSubData(i)
If .hWnd <> 0 Then 'If not previously Subclass_Stop'd
' Debug.Print .hWnd, mParentHwnd
'Prevents crash if there are multiple controls on the form, because the Form is subclassed for MouseDown events
If .hWnd = mParentHwnd Then
If wasHere = False Then
' Call Subclass_Stop(.hWnd)
End If
wasHere = True
Else
Call Subclass_Stop(.hWnd) 'Subclass_Stop
End If
End If
End With
i = i - 1 'Next element
Loop
End Sub
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
Ssubtmr6.dll has a memory leak that will eventually crash Vb. It depends on how much memory you have, how many instances of the subclassed usercontrol are on the Form, and finally how many times the Form is Loaded/Unloaded. Also check to make sure that for every AttachMessage there is a corresponding DetachMessage when using Ssubtmr6.dll. You may want to try one of the subclassing Thunks on Planet Source Code.
Last edited by DrUnicode; Dec 1st, 2008 at 07:48 AM.
In the SubClassed UserControl, you should probably have a Subclass_StopAll function. Find it and change it to this:
Its nice to you to show me your example, but its just not works. I am getting subscript out of range error codes, i also dont know where and how should i set the parent hwnd (mParentHwnd)!
Its nice to you to show me your example, but its just not works. I am getting subscript out of range error codes, i also dont know where and how should i set the parent hwnd (mParentHwnd)!
Ohh yea I forgot about mParentHwnd : )
Decalre this in the General Declaration Section.
Code:
Private mParentHwnd As Long 'Remember parent Hwnd to stop crash
Then in your UserControl_ReadProperties add this.
Code:
mParentHwnd = UserControl.Parent.hWnd
--------------------
The Subscrit Out Of Range errors, are other coding errors you have, which can be tracked down through simple error coding in the subs.
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
Nevermind, its ok now. About the array issue, i found that the line i = UBound(sc_aSubData()) is raised the error, because in design time havent got dimensions of the array, therefore it have no upper bound. It is also fixed now.
I still got a crash once in IDE. But later there were no problems! By regarding LaVolpe's post, this wouldnt solve the problem. I will do some test to see it is stable or not.
You can usually avoid IDE crashes caused by subclassing by only using your programs controls to close the app.
In other words, don't use the vb6 Stop button.
Edited: This becomes even more crash prone when you have other UCs (3rd party) that subclass the parent also. The order of subclassing/unsubclassing is not in your control. And if those others use similar subclassing techniques as does your uc, what a mess! Which is the reason I don't write UCs to subclass any container/outside object, unless subclassing starts in a sub/function and terminates subclassing before the sub/function terminates.
i'm facing issues with subclassing uc
i created a listview window on vb uc
then subclass the uc to get messages,
one of the issues for example is:
the uc doesn't get some messages if there is no other control
on the uc parent
if i place the uc on an empty form, some messages simply don't arrived
i put debug.print in the wndproc, to print all the messages
i downloaded stuff from vbaccelerator to learn.
but any idea on how to get messages without subclassing
the uc would be helpfull.