Results 1 to 6 of 6

Thread: [RESOLVED] Vb6 - prevent error on api calls

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Resolved [RESOLVED] Vb6 - prevent error on api calls

    Let's say you made an EXE that uses a certain API present on Win98 and now this API is no longer present on Win7/Win8.

    Is using "on error goto" enough to prevent the crash or the exe is going to be useless anyway no matter the error handling ?

    In other words, to you recommend to use error handling for an API that you think it may no longer work in the future ?

    I dont understand much about API calls thats why Im askin.

    thanks, regards

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Vb6 - prevent error on api calls

    When in doubt, try it out!
    Code:
    Option Explicit
    
    Private Declare Sub FuzzNut Lib "fuzzlib" (ByVal Number As Long)
    
    Private Sub Form_Load()
        On Error Resume Next
        FuzzNut 37
        If Err Then
            MsgBox Err.Description
        Else
            MsgBox "It's all good"
        End If
        On Error GoTo 0
        MsgBox "Got here!"
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: Vb6 - prevent error on api calls

    Ok and what about the declaration part in the beginning ?
    Declaring an API that is no longer present will crash the app ?

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

    Re: Vb6 - prevent error on api calls

    Quote Originally Posted by horazio View Post
    Ok and what about the declaration part in the beginning ?
    Declaring an API that is no longer present will crash the app ?
    Using an obsolete API declaration or a typo in an API declaration's name or function will not crash the app on its own. You will get a trappable error returned, when the API is called, saying that the DLL function could not be found. If you are not trapping for such errors, then app will crash.

    If you are using an API function in your app and that function, for whatever reasons, is no longer supported on future operating systems, I'd say what difference does it really matter in the long run? Odds are that your app won't work correctly without the API anyway. Sure, it would be nice to be able to show a message box, "Expected DLL function not found: xxxxx.dll". The overall results will be pretty much the same -- your app won't work.

    If you truly want to test APIs to see if they exist, you can build a start-up routine that can do that. You'd use LoadLibrary to attempt to load the dll into your process, then use GetProcAddress to test for your API functions in that DLL, then FreeLibrary when done testing.

    If you are creating apps for money, it would be a smart investment to find/buy operating systems when they are released. Test your apps on those new operating systems to see if they still work as expected
    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}

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: Vb6 - prevent error on api calls

    Quote Originally Posted by lavolpe View Post
    using an obsolete api declaration or a typo in an api declaration's name or function will not crash the app on its own.

    word.

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Vb6 - prevent error on api calls

    If you actually test the code in post 2 (and try remming out all the code in the Form_Load event) you will see that the Declare does not 'crash the app'.

Tags for this Thread

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