Re: Err Object Anomaly Bug in VB6+SP5 and How to Reproduce

Tech-Archive recommends: Fix windows errors by optimizing your registry



> The program instability is likely caused by not unhooking your WindowProc
> properly on application shutdown. (Won't happen if you just let the
> application crash!)

In the sample I am not doing it because VB6 will never reach the line that
UnSubClass it. In my real App, I am doing it. I wanted to keep the sample as
small as possible.

> Public gfForm1 as Form1
>
> Sub Main()
> Set gfForm1=New Form1
> gfForm1.Show
> End Sub

I tried that. It shows the following messages then the CPU usage goes near
100%. gfForm1 is never shown. I replaced Form1 references in the code as
appropriate, i.e., changed 'Form1.Caption =' to 'gfForm1.Caption =':

Main called
Form_Load called, Form1 Load Counter = 1

I also used SubClass/UnSubClass code in the instance above. Also, I used a
Form2 instead of CreateWindowEx, then used gfForm1 instead of Form2. The
result above is when subclassing gfForm1. Here are my subclassing routines,
called in Form Load/Unload events:

Public Sub SubClassForm(ByVal h As Long)
m_hWnd = h
m_OldProc = SetWindowLong(h, GWL_WNDPROC, AddressOf FormWindowProc)
End Sub

Public Sub UnSubClassForm(ByVal h As Long)
If m_OldProc <> 0 Then
m_OldProc = SetWindowLong(h, GWL_WNDPROC, m_OldProc)
End If
End Sub


P.S.: I have been using VB since version 1.0, so I am not a beginner, not
that you thought I am...


"Sean Myers" <seanm@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eEMv2HA0FHA.2932@xxxxxxxxxxxxxxxxxxxxxxx
> More of a guess than a genuine solution...(experts feel free to correct me
> :-) )
>
> I would guess that the form instance (Form1) crashes, but the O/S is still
> calling into that memory space, and the WindowProc attempts to access the
> instance Form1 which is crashed causing the second dialog with a messed up
> count. The program instability is likely caused by not unhooking your
> WindowProc properly on application shutdown. (Won't happen if you just let
> the application crash!)
>
> Several things you may wish to consider:
> 1) Use an explicit instance of Form1.
> in module:
> Public gfForm1 as Form1
>
> Sub Main()
> Set gfForm1=New Form1
> gfForm1.Show
> End Sub
>
> Check in your WindowProc to see if gfForm1 is nothing
>
> 2) Unhook your WindowProc on program termination.
> 3) Handle that error properly!
> I'm not sure what you mean by Err object instability. I have never
> experienced any problems with the Err object.
>
> HTH,
> Sean
>


.



Relevant Pages

  • Re: Not showing forms outline when resizing
    ... specific aspect ratio while he is doing so? ... Private Sub Form_Load ... Private Const GWL_WNDPROC As Long = ... AddressOf WindowProc) ...
    (microsoft.public.vb.general.discussion)
  • Re: How can I throw out (handle) an ENTER keypress for an AcceptButton?
    ... that Form1 was receiving a KeyUp from a key press that occurred on Form2. ... My app starts with Form1 which has a textbox on it. ... KeyUp event of the textbox for that. ... > Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Shared Method Problem With "Global" Storage
    ... a routine in Module1 which then calls code back in Form1 ... ButtonHasBeenClicked but the reference to ButtonHasBeenClicked ... instance member of a class from within a shared method or shared ... In a shared Sub, you can not access an instance field withouth ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Err Object Anomaly Bug in VB6+SP5 and How to Reproduce
    ... - Form1 is destroyed and reloaded. ... subclass procedure, but I am accessing them in event procedures called by ... Private Sub Form_Load ... Private Sub Form_Click ...
    (microsoft.public.vb.bugs)
  • Re: Instanzen von identischen Formen ?
    ... Projekt mit ein Form: Form1 ... Private Sub Main() ... End With ... With FormB ...
    (microsoft.public.de.vb)