VB.NET API General : How Do I Use The API in VB.NET
Q: How do I use APIs in .NET?
A: If you come from a VB 6 background, you probably are accustomed to Declaring APIs like :
Private Declare Function SetSysColors Lib "user32" _
(ByVal nChanges As Long, lpSysColor As _
Long, lpColorValues As Long) As Long
The breakdown of this can be:
Declare indicates that you will be using an "external" function.
SetSysColors is the name of the external function
Lib "user32" Indicates that the SetSysColor function is present in the User32.dll
Then the argumants are listed in brackets
If you were to use the exact same declaration inside VB.NET, you would notice that it is acceptable.
Q: But, is it really?
A: Well, it should logically work, but you may not always get away with this declaration inside VB.NET
A: The major headache would be the datatypes. Sometime an API would be declared using Integers and it will not work properly. In this article, I've outlined the Unmanaged types. In VB 6, we could have used a Long type variable to hold the value of a Window's handle, in VB.NET we must and should use the IntPtr type variable.
Q: What should the proper Declaration in .NET look like?