Calling Windows API Functions

One of the major features of .NET is that it is platform independent. However, there are many powerful functions available in the Windows API, so there is little doubt that some developers will want to a call Windows API function from time to time. Fortunately, VB .NET includes the Declare statement, which allows you to call Windows API functions.

The Declare statement in VB .NET is very similar to the one from VB6, with some minor modifications. You might recall from your VB6 work that functions have both an ANSI and a Unicode implementation in the API: an A suffix means the ANSI version, whereas a W suffix indicates Unicode. Examine the following sample Declare statement:

 Declare Function GetComputerName Lib "kernel32.dll" ...

Get A Programmer's Introduction to Visual Basic® .NET 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.