Page 2 of 2 FirstFirst 12
Results 41 to 50 of 50

Thread: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

  1. #41

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    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
    Attached Files Attached Files
    Last edited by Jim Davis; Nov 30th, 2008 at 03:58 AM.

  2. #42
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Subclassing usercontrols (Previously: App closing sequence)

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #43

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Subclassing usercontrols (Previously: App closing sequence)

    Oh thanks! I will look forward how to avoid and/or replace these methods to get the proper functionality.

    Thanks for informing me!

  4. #44
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    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:
    1. 'Stop all subclassing
    2. Private Sub Subclass_StopAll()
    3.   Dim i As Long
    4.   Dim getControlNo As Single
    5.   Dim wasHere      As Boolean
    6.  
    7.    
    8.   i = UBound(sc_aSubData())                                                             'Get the upper bound of the subclass data array
    9.   Do While i >= 0                                                                       'Iterate through each element
    10.     With sc_aSubData(i)
    11.       If .hWnd <> 0 Then                                                                'If not previously Subclass_Stop'd
    12.            ' Debug.Print .hWnd, mParentHwnd
    13.            'Prevents crash if there are multiple controls on the form, because the Form is subclassed for MouseDown events
    14.             If .hWnd = mParentHwnd Then
    15.                 If wasHere = False Then
    16.                   ' Call Subclass_Stop(.hWnd)
    17.                 End If
    18.                 wasHere = True
    19.             Else
    20.                 Call Subclass_Stop(.hWnd)                                                       'Subclass_Stop
    21.             End If
    22.       End If
    23.     End With
    24.    
    25.     i = i - 1                                                                           'Next element
    26.   Loop
    27. 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.



  5. #45
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    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.

  6. #46

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    Quote Originally Posted by some1uk03
    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)!

  7. #47
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    Quote Originally Posted by Jim Davis
    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.



  8. #48

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    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.

  9. #49
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: [RESOLVED] Subclassing usercontrols (Previously: App closing sequence)

    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.

  10. #50
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Subclassing usercontrols (Previously: App closing sequence)

    Quote Originally Posted by LaVolpe View Post
    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width