How to Add API
An API is a DLL file you use to call external libraries in your .NET applications. The Windows operating system provides an API with several DLL files you can use in your .NET code. You must identify the DLL file in your code in order to call a function from the API DLL file.
Instructions
-
-
1
Open the Visual Studio software form the Windows "Start" menu. Open the project in which you want to call the DLL API.
-
2
Double-click the .NET source code file you want to use to call the DLL function. The code editor opens.
-
-
3
Add the DLL API code. You must know the DLL file you want to import. For instance, the following code adds the "MessageBox" function from the "user32.dll" API in Windows:
Declare Auto Function MBox Lib "user32.dll" Alias "MessageBox" (
ByVal hWnd As Integer,
ByVal txt As String,
ByVal caption As String,
ByVal Typ As Integer) As IntegerCopy this code as-is; otherwise, the Windows API returns an error.
-
4
Use the API function in your code. Using the "MessageBox" function, the following code calls the function and displays the box on the user's desktop:
Dim success As Integer
success= MBox(0, "Testing Function", "This text displays on the desktop.",
MB_ICONQUESTION Or MB_YESNO)
-
1