-
Jan 23rd, 2012, 02:42 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jan 23rd, 2012, 04:56 AM
#2
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
-
Jan 23rd, 2012, 05:56 AM
#3
Thread Starter
Hyperactive Member
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 ?
-
Jan 23rd, 2012, 08:51 AM
#4
Re: Vb6 - prevent error on api calls
Originally Posted by horazio
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
-
Jan 23rd, 2012, 09:03 AM
#5
Thread Starter
Hyperactive Member
Re: Vb6 - prevent error on api calls
Originally Posted by lavolpe
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.
-
Jan 23rd, 2012, 07:42 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|