dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 42

Thread: Using the Call statement

  1. #16
    Phil Weber Guest

    Re: Using the Call statement

    > The best option is to make the choice of alerts user-
    > configurable: sound, message box, flashing caption,
    > whatever...


    Bob: No argument there. But I have no problem with sounds as long as they're
    subtle and pleasant. Have you used MS Money? I think its use of sound is
    exemplary (and yes, you can turn it off! ;-)
    ---
    Phil Weber



  2. #17
    Mattias Sjögren Guest

    Re: Using the Call statement

    Bob,

    >Do you have a reference or more info? I don't remember seeing that.


    All I have is the original bug description that I sent to Microsoft
    back in march (included below). I know Brad Martinez helped me
    research the details, and I think the conclusion was that VB indeed
    generates incorrect code. I don't think the issue has very high
    priority on Microsoft's fix list though, and I haven't seen a KB
    article or anything about it.


    Mattias

    ===
    Mattias Sjögren (VB MVP)


    When you call an API that returns an ANSI BSTR string, and discard the
    return value by using the Call keyword, the program crashes due to an
    access violation. The only MS API that comes to mind that I can use to
    demo this is SysAllocStringByteLen. But the same thing happens if you
    call custom APIs, so the bug is not tied to that particular function.

    Declare Function SysAllocStringByteLen Lib "oleaut32" ( _
    ByVal psz As String, _
    ByVal length As Long) As String

    Const TestStr As String = "Hello World"

    ' This works
    Dim s As String
    s = SysAllocStringByteLen(TestStr, Len(TestStr))

    ' This too
    MsgBox SysAllocStringByteLen(TestStr, Len(TestStr))

    ' But this will crash
    Call SysAllocStringByteLen(TestStr, Len(TestStr))


    Some observations:
    * It only crashes if you compile to native code. PCode executables
    seem to work.
    * It crashes on Windows NT and 2000, but not on Windows Me.
    * It doesn't crash if you call an API that returns a Unicode BSTR
    using a type library. This, and the fact that the exception is thrown
    somewhere within MultiByteToWideChar, leads me to believe that the bug
    has something to do with the ANSI->Unicode conversion VB does.


  3. #18
    Michael Culley Guest

    Re: Using the Call statement

    I specifically remember this very problem with Microsoft Basic a *very* long
    time ago, but it wasn't VB, it was Microsoft Basic for the microbee
    (microbee was an australian computer company so maybe not everyone knows
    microbees). This was some time around 1983. There was a function to call a
    memory address and things went really haywire if you didn't use call or grab
    the return value. Who knows, maybe this carried over to VB.

    --
    Michael Culley
    www.vbdotcom.com


    "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
    news:3c212a99@147.208.176.211...
    > Bob,
    >
    > >Do you have a reference or more info? I don't remember seeing that.

    >
    > All I have is the original bug description that I sent to Microsoft
    > back in march (included below). I know Brad Martinez helped me
    > research the details, and I think the conclusion was that VB indeed
    > generates incorrect code. I don't think the issue has very high
    > priority on Microsoft's fix list though, and I haven't seen a KB
    > article or anything about it.
    >
    >
    > Mattias
    >
    > ===
    > Mattias Sjögren (VB MVP)
    >
    >
    > When you call an API that returns an ANSI BSTR string, and discard the
    > return value by using the Call keyword, the program crashes due to an
    > access violation. The only MS API that comes to mind that I can use to
    > demo this is SysAllocStringByteLen. But the same thing happens if you
    > call custom APIs, so the bug is not tied to that particular function.
    >
    > Declare Function SysAllocStringByteLen Lib "oleaut32" ( _
    > ByVal psz As String, _
    > ByVal length As Long) As String
    >
    > Const TestStr As String = "Hello World"
    >
    > ' This works
    > Dim s As String
    > s = SysAllocStringByteLen(TestStr, Len(TestStr))
    >
    > ' This too
    > MsgBox SysAllocStringByteLen(TestStr, Len(TestStr))
    >
    > ' But this will crash
    > Call SysAllocStringByteLen(TestStr, Len(TestStr))
    >
    >
    > Some observations:
    > * It only crashes if you compile to native code. PCode executables
    > seem to work.
    > * It crashes on Windows NT and 2000, but not on Windows Me.
    > * It doesn't crash if you call an API that returns a Unicode BSTR
    > using a type library. This, and the fact that the exception is thrown
    > somewhere within MultiByteToWideChar, leads me to believe that the bug
    > has something to do with the ANSI->Unicode conversion VB does.
    >




  4. #19
    Michael Culley Guest

    Re: Using the Call statement

    Phil,

    I'm writing an addin for VB right at this very moment (OK I'm writing this
    message at this very moment). The user specifies a class to have code added
    and pushed the GO button. My addin checks to see if the class is checked-in
    to sourcesafe and if it is, it gives a message and does not continue. If I
    used anything except a messagebox I think it would confuse the user. Most
    likely they would think it was still running and just sit there waiting.
    After a while they would work out the file wasn't checked out and think 'why
    didn't the app say something'. It did, just they had their speakers turned
    off.

    --
    Michael Culley
    www.vbdotcom.com


    "Phil Weber" <pweberonline@fawcette.com> wrote in message
    news:3c21278c@147.208.176.211...
    > > The best option is to make the choice of alerts user-
    > > configurable: sound, message box, flashing caption,
    > > whatever...

    >
    > Bob: No argument there. But I have no problem with sounds as long as

    they're
    > subtle and pleasant. Have you used MS Money? I think its use of sound is
    > exemplary (and yes, you can turn it off! ;-)
    > ---
    > Phil Weber
    >
    >




  5. #20
    Phil Weber Guest

    Re: Using the Call statement

    > My addin checks to see if the class is checked-in to sourcesafe
    > and if it is, it gives a message and does not continue.


    Michael: How about a non-modal window that automatically dismisses itself
    after a preset timeout (say, 5 seconds)? Or a balloon-style tooltip pointing
    at the file name and saying something like, "This file is already checked
    in?"

    My primary objections to OK-only message boxes is that they steal the focus
    and interrupt what the user is doing, forcing him to dismiss the message
    before the program can continue. Non-modal, auto-dismissing messages can
    inform the user without such obnoxious behavior.
    ---
    Phil Weber



  6. #21
    Dean Earley Guest

    Re: Using the Call statement

    > What sorts of messages do you consider sufficiently important that they
    > justify interrupting the user?


    "This program isn't registered, go away"
    "Oops, I cant find this dependency"

    Either of those?

    If I was expecting something to happen and something was wrong, I'd expect a message, not a label somewhere.

    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems



  7. #22
    Jim Pragit Guest

    Re: Using the Call statement


    Hi Phil,

    "Phil Weber" <pweberonline@fawcette.com> wrote:
    >My primary objections to OK-only message boxes is that they steal the focus
    >and interrupt what the user is doing, forcing him to dismiss the message
    >before the program can continue.


    I most definitely agree when a MsgBox is displayed on a LostFocus, Change,
    Click or Validate event, but what if the MsgBox is a direct response to an
    action the user initiates? For example, the user clicks the OK or Save button
    on a form and the program displays a MsgBox because there's a data validation
    error that prevents the data from being saved. In this case, you're really
    not interrupting the user because the fact that he/she clicked the OK/Save
    button means they were done with the form.

    >Non-modal, auto-dismissing messages can
    >inform the user without such obnoxious behavior.


    But this too leads to other problems. What if the user is about to run a
    process that takes more than a second or two? He/she may switch to another
    program or just go to lunch. The user would never see a non-modal, auto-dismiss
    message box.

    I'm not saying MsgBox's can't be misused, but I do think there are situations
    where they're perfectly acceptable.

    Also, a comment to something you said before - not all computers have sound
    cards. About half the computers at my client do not have sound cards.

    - Jim

  8. #23
    Jim Pragit Guest

    Re: Using the Call statement


    Hi Bob,

    I don't care too much for apps making sounds at me either, especially web
    pages. BTW, have you ever tried Gozilla? It's one of the most incredibly
    annoying programs ever created sound wise. Fortunately, the sound can be
    turned off.

    Another point about sounds in apps to notify the user of something - if the
    user is listening to a CD or an MP3, the sound could easily be drowned out.

    - Jim

    "Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    >I haven't used MS Money for a long time now but I can guarantee that I
    >wouldn't like the sound. There's just something about applications making
    >sounds at me that just drives me nuts. I much prefer total silence while
    >working. Sounds might be a great option for somebody else but I'll take

    a
    >good old message box any day!



  9. #24
    Eric D. Burdo Guest

    Re: Using the Call statement


    Thank you for the reponses. I could not get any proof from him that the Call
    statement made any difference.

    Many thanx!

    Eric

  10. #25
    Jim Pragit Guest

    Re: Using the Call statement


    "Jim Pragit" <NoSpam@NoSpam.com> wrote:
    >
    >I most definitely agree when a MsgBox is displayed on a LostFocus, Change,
    >Click or Validate event,


    To avoid confusion, I meant a Click event on a ListBox or ComboBox.

    - Jim



  11. #26
    Bob Butler Guest

    Re: Using the Call statement


    "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
    news:3c212a99@147.208.176.211...
    > Bob,
    >
    > >Do you have a reference or more info? I don't remember seeing that.

    >
    > All I have is the original bug description that I sent to Microsoft
    > back in march (included below). I know Brad Martinez helped me
    > research the details, and I think the conclusion was that VB indeed
    > generates incorrect code. I don't think the issue has very high
    > priority on Microsoft's fix list though, and I haven't seen a KB
    > article or anything about it.


    Thanks, that's interesting and good to know. I don't remember ever dealing
    with a call that returns a BSTR which is probably why I never ran into it.



  12. #27
    Bob Butler Guest

    Re: Using the Call statement


    "Phil Weber" <pweberonline@fawcette.com> wrote in message
    news:3c21278c@147.208.176.211...
    > > The best option is to make the choice of alerts user-
    > > configurable: sound, message box, flashing caption,
    > > whatever...

    >
    > Bob: No argument there. But I have no problem with sounds as long as

    they're
    > subtle and pleasant. Have you used MS Money? I think its use of sound is
    > exemplary (and yes, you can turn it off! ;-)


    I haven't used MS Money for a long time now but I can guarantee that I
    wouldn't like the sound. There's just something about applications making
    sounds at me that just drives me nuts. I much prefer total silence while
    working. Sounds might be a great option for somebody else but I'll take a
    good old message box any day!




  13. #28
    Ken Halter Guest

    Re: Using the Call statement

    Well.. I'd have to search around for an app that I've written that uses this
    type of "Ok Only" type message but.. the first thing that comes to mind is
    "Serial Port Not Responding"... going on to say that their only choice would
    be to correct whatever it was that was causing this and restart the
    program.. I saw mention of sounds.. that's a complete no go in any of my
    apps.. here at work, I write code for automated factory machinery.. sounds
    would never be heard. At home, my speakers are turned on only when playing a
    game (which isn't very often).. I guess I could disable everything and make
    a label flash or what ever.. but I can't see how that would be better (or
    less "Rude") than a message box.

    --
    Ken Halter
    MS-MVP-VB
    http://www.vbsight.com
    Please respond only to the newsgroups so all can benefit.
    Besides.. I check my email only once a week :-)

    "Phil Weber" <pweberonline@fawcette.com> wrote in message
    news:3c2106a1@147.208.176.211...
    > > Looks like a case of personal choice...

    >
    > Ken: Agreed. What I've stated are my opinions. But I'm confident in their
    > correctness because I've never met a user who prefers a MsgBox after

    having
    > seen alternative methods of communication.
    >
    > > If there's a message that's important enough to pop up
    > > a simple dialog so the user can't simply ignore it, I choose
    > > a message box.

    >
    > What sorts of messages do you consider sufficiently important that they
    > justify interrupting the user?
    > ---
    > Phil Weber
    >
    >




  14. #29
    Michael Culley Guest

    Re: Using the Call statement

    > Also, a comment to something you said before - not all computers have
    sound
    > cards. About half the computers at my client do not have sound cards.


    Or even worse, like most of the machines here, they have a sound card built
    in to the motherboard but no speakers. So the program might be more sound
    orientated on these machines.



  15. #30
    Michael Culley Guest

    Re: Using the Call statement

    Phil,

    I don't totally disagree with what you say, I think they can be over used.
    But I give standard behaviour alot of weight and I think in this situation
    the standard behaviour would be to show a messagebox. Anything else has the
    big potential to confuse the user.

    > forcing him to dismiss the message
    > before the program can continue


    But this is required in this situation as it is vital for the user to see
    this message. The fact that he/she must click it, means that they have
    acknowledged it. Every other option you have presented has more chance of
    the message being missed.

    <$0.02>
    I think some programmer go too far with messageboxes, but I think you are
    going too far away from them.
    </$0.02>

    --
    Michael Culley
    www.vbdotcom.com


    "Phil Weber" <pweberonline@fawcette.com> wrote in message
    news:3c2181b5$1@147.208.176.211...
    > > My addin checks to see if the class is checked-in to sourcesafe
    > > and if it is, it gives a message and does not continue.

    >
    > Michael: How about a non-modal window that automatically dismisses itself
    > after a preset timeout (say, 5 seconds)? Or a balloon-style tooltip

    pointing
    > at the file name and saying something like, "This file is already checked
    > in?"
    >
    > My primary objections to OK-only message boxes is that they steal the

    focus
    > and interrupt what the user is doing, forcing him to dismiss the message
    > before the program can continue. Non-modal, auto-dismissing messages can
    > inform the user without such obnoxious behavior.
    > ---
    > Phil Weber
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center