Name

Err.LastDLLError Property

Class

Microsoft.VisualBasic.ErrObject

Syntax

Err.LastDLLError

Description

A read-only property containing a system error code representing a system error produced within a DLL called from a VB program.

Rules at a Glance

  • Only direct calls to a Windows system DLL from VB code will assign a value to LastDLLError.

  • The value of the LastDLLError property depends upon the particular DLL being called. Your code must be able to handle the various codes that can be returned by the DLL you are calling.

  • Don’t forget that a failed DLL call does not itself raise an error within your VB program. As a result, the Err object’s Number, Description, and Source properties are not filled.

Programming Tips and Gotchas

  • The LastDLLError property can be changed by VB at any time, so it is important to save the value in an independent variable as soon as possible.

  • The LastDLLError property is only used by system DLLs, such as kernel32.dll. Therefore, errors that occur within DLLs you may have created will not cause an error code to be assigned to the property.

  • Obtaining accurate documentation about the return values of system DLLs can be a challenging experience! Most useful information can be found by studying the API documentation for Visual C++. However, you can use the Win32 API FormatMessage function to return the actual Windows error message string from within Kernel32.DLL, which incidentally will also be in the correct language. The following is a brief example that you can ...

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.