Understanding P/Invokes

Calls to Windows API functions are known as Platform Invokes or P/Invokes. The Visual Basic programming language offers two ways for performing platform invokes:

Declare keyword

System.Runtime.InteropServices.DllImport attribute

The Declare keyword has a behavior similar to what happened in Visual Basic 6, and it has been kept for compatibility, but you should always prefer the DllImport attribute because this is the one way recognized by the Common Language Specification. Now we can see how to declare a P/Invoke. The next example considers the PathIsUrl function, from the Shlwapi.dll system library, which checks if the specified is an URL and returns a value according to the result. This is with the Declare keyword: ...

Get Visual Basic® 2010 Unleashed 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.