Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Apr 20, 1999

Never use the GetLastError API function

If you heavily use API calls and strictly follow the SDK documentation, you might be tempted to use the GetLastError API to retrieve the error returned by your last API function or procedure. However, this function doesn't always return valid error codes, because Visual Basic internally does a lot of calls to the Windows API, therefore it is highly likely that the value returned by the GetLastError function actually refers to one of those internal calls, rather than your most recent explicit call.

To work around this problem, just use the LastDLLError property of the Err object. Visual Basic always caches in this property the error code returned by any call to a routine to the Windows API. Unfortunately, you cannot disable this mechanism, which means that all your calls to the API are slowed down, even if you're not interested in error codes.

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date