Re: Error on Exit Sub

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: MacDermott (macdermott_at_NoSpam.com)
Date: 05/25/04


Date: Mon, 24 May 2004 21:24:16 -0400

Wow!
I'm impressed that my little problem (and my very modest knowledge of VB)
have come to the attention of THE Randy Birch.
(I've used some of your code in other places, and am extremely grateful for
it.)

Unfortunately, this problem just came to our attention a few days ago; we've
been on this project for about a year, and are due to release our final beta
this week.
    So while my boss was happy to have me build a wrapper function to trap
out any errors from the API call, he wasn't ready for me to start learning
about windows messages and trying to apply that to this application at this
point.
    Frankly, though, I'm almost hoping that potential users complain about
some of the flicker and jumpiness, so we can get some funding to look into
your suggestions. They sound truly inviting, and I sure wish I'd posted
asking about such things earlier.

    There may be some unused API declarations hanging around in other parts
of the code, but I'm really not comfortable enough to write my own
(especially with UDTs), so anything that's there has been copied/pasted from
someone else's website. I'd hope that reduces the likelihood of erroneous
declarations. I really appreciate the heads-up on that possibility, though.

    So here's the situation as I grasp it at this moment:
        LockWindowUpdate 0 returns an error code of 87, which I can trap and
discard with fair certainty that it's just telling me the window wasn't
locked in the first place.
        It also sometimes returns an error code of 997, which I don't
understand, but am taking on faith that it's also not anything I need to
worry about.
        If I don't trap this error out and resolve it, it makes trouble when
I issue an Exit Sub command - perhaps because when VB goes to clean up the
Err object it's troubled by having a 0 in the Number property, but an 87 in
the LastDLLError property?

    I'm still curious about the error code of 997, and some other posts
suggest that my analysis of the error at Exit Sub may not be correct - but
I'm not sure I understand the reasoning there, either.

Thanks so much for your interest and attention!
    - Turtle

"Randy Birch" <rgb_removethis@mvps.org> wrote in message
news:%23UlBH4dQEHA.1388@TK2MSFTNGP09.phx.gbl...
> re: the LockWindowUpdate problem: Error 87 is "The parameter is
> incorrect.", and in the case of passing 0& to the call I suspect is
Windows'
> way of saying "there was nothing locked". LockWindowUpdate is not always
the
> best solution because of the side effects of the call .. the flickering
> desktop to be precise.
>
> Were you not successful with SendMessage and WM_SETREDRAW?
>
> If you are not calling any Doevents in the procedure for which you've
> determined you need to lock the window, you can achieve the same effect
> without any api by simply setting the appropriate control's visible
property
> (or the form itself for that matter) to False before the long process, and
> true thereafter. The control/form won't disappear, but its internal
> redrawing will be suspended while in its invisible state. If you do
> introduce a doevents or other call yielding to the system, the
control/form
> will disappear. Therefore used judiciously this is an excellent way to
speed
> up the modification of the data in a control. And for a listview it's the
> only real solution, since internally the control turns redrawing on every
> time an item is added or deleted.
>
> re: the exit sub error: You state "there are no other APIs in the
> vicinity". That doesn't mean that an improperly declared API (especially
one
> expecting UTDs as parameters) will not corrupt memory and lead to
erroneous
> errors when the call is executed. I've had this before, the last time was
> when working out the code to enumerate the protected file system with
> SfcGetFiles. The problem was a mis-sized UDT.
>
> --
>
> Randy Birch
> MVP Visual Basic
> http://vbnet.mvps.org/
> Please respond only to the newsgroups so all can benefit.
>
>
> "Turtle MacDermott" <macdermott@nospam.com> wrote in message
> news:#hiT5GcQEHA.2404@TK2MSFTNGP12.phx.gbl...
> : Once again, many thanks for the ideas -
> : sometimes I think I'm understanding more of this -
> : then I realize there's another whole part I hardly understand at
> : all.
> : I really appreciate you folks staying with me on this.
> :
> : Here's what I did:
> : I replaced all calls to LockWindowUpdate 0 with a wrapper function
> which
> : calls LockWindowUpdate 0, then checks for a non-zero Err.LastDLLError.
> : At first, I had it only eat return values of 87 -
> : but I quickly found that it was sometimes returning 997 -
"Overlapped
> : I/O Operation is in progress".
> : Mr. Google has been singularly un-helpful in explaining to me what
> might
> : be causing this exception.
> : However (not too surprisingly), when I rewrote the wrapper function
to
> : suppress any LastDLLError, my application stopped throwing errors.
> : Again, I'm getting perilously close to "removing error
trapping",
> : but since my window seems to get unlocked, I guess in some sense I have
a
> : functioning application.
> :
> : To this comment:
> : My hunch is that you /really/ have a bad parameter#
> : This is certainly the only API call in the vicinity.
> : In this "error condition", I find that
> : LockWindowUpdate 0
> : returns a value of 87.
> : LockWindowUpdate Me.Hwnd
> : returns a value of 0.
> : After I've executed with Me.Hwnd, I can then re-execute with 0,
> and
> : get a return value of 0.
> : So it sure looks to me as if I don't have any window locked when I
> pass
> : the 0, and this IS the bad parameter#.
> :
> : BTW - What is an IsWindow check?
> :
> : = Turtle
> :
> :
> :
> : "J French" <erewhon@nowhere.com> wrote in message
> : news:40b1e68b.10013346@news.btclick.com...
> : > On Mon, 24 May 2004 06:07:33 -0400, "MacDermott"
> : > <macdermott@NoSpam.com> wrote:
> : >
> : > >Thanks for your thoughts on this.
> : > >As you'll see elsewhere in this thread, I've narrowed the problem
down
> to
> : > >the API call, which is trying to unlock a window that's not locked.
> : > >This causes my Err object to have a non-zero .LastDLLError property,
> : while
> : > >its own .Number property remains zero.
> : > >I wonder if this could be the object that VB is having a problem
> : destroying.
> : >
> : > My hunch is that you /really/ have a bad parameter#
> : >
> : > - something like an API declaration for a Function where the return
> : > type is not declared.
> : >
> : > In such a case an extra parameter is added to the stack to return the
> : > Variant .... unless you have DefInt A-Z at the top of your module
> : > (personally I use DefObj A-Z ... but that is a different matter )
> : >
> : > - or an 'Any' that is ByRef rather than ByVal
> : >
> : > However, the LockWindowUpdate can be tested very easily
> : >
> : > Scan the entire project for DLL declarations of LockWindowUpdate and
> : > zap them (Ahem - comment them out)
> : >
> : > Then front LockWindowUpdate with a VB Function that remembers whether
> : > any Window was locked,
> : > - shrieks at you if you try to Unlock when nothing was locked
> : > - Does an IsWindow check
> : > - examines LastDllError
> : >
> : > Personally (and I am very interested in this problem) I reckon that it
> : > is another API - not LockWindowUpdate
> : >
> : > Please, before you do any of the above, back up thoroughly.
> : >
> : > BTW
> : > - TP's suggestion would be something I would go for
> : > (and suggest you check for anyway)
> : > - if the problem were not so /very/ similar to my recent API cockup.
> : >
> : > HTH
> :
> :
>



Relevant Pages

  • Re: File browser
    ... However, since the API isn't doing what I want, it was my interpretation of the other posts that it was _possible_ that the failure of the API to do what I wanted was due to the improper initialization. ... messages for a specific window handle are delivered only to the message pump running in the same thread that created the window handle. ... And Windows strictly enforces the rule about calling the window procedure; granted, the code that implements the procedure could always call it directly, but if you go through the normal PostMessage/SendMessage API that you're supposed to use, Windows will always cause the execution of the window procedure needed for handling those calls to happen on the same thread that created the window handle. ...
    (comp.lang.java.programmer)
  • Learning Quartz API? Am I on the right track here?
    ... The purpose of the API is pretty simple, it just wraps up the platform ... specific details of instancing a window, ... So I'm asking here, #1 is it worth my time to worry about Quartz, ...
    (comp.sys.mac.programmer.help)
  • Re: Drag-and-drop from Windows Explorer?
    ... >that is not a function of delphi but of the win32 api. ... >to register the form as a window that will accept the ... >free the memory via the handle that was given you. ...
    (comp.lang.pascal.delphi.misc)
  • Re: MPEG2 Video Capture to a BMP
    ... >> We have an application that has a propriotary mpeg2 player. ... The API of the ... >video capture from web cam devices, etc. and I think I am on the right path ... >create a capture window and this happens, ...
    (microsoft.public.dotnet.framework)
  • Re: Word documents disappear
    ... Many things are vying for my attention. ... I have reset the system shortcuts. ... When I have done this it is only the window I am working on that disappears. ... You might also be triggering the system-wide Hide command, ...
    (microsoft.public.mac.office.word)