The simplest example of compiling and calling DLL in VB. NET, and the compiling example of vb. netdll
DLL (Dynamic Link Library) is a very useful thing. It is very important to develop large projects, because when many people cooperate in development, they can assign a task to each person and use DLL to complete it, when combined, there will be no conflict. Here is the simplest DLL compiling and calling example. I am not very familiar with it.
First, Open VB. NET, select the class library, and change the name to test.
Then enter the following code:
Public Class test
Public Function test (ByVal a As Long, ByVal B As Long) As Long
Return a + B
End Function
End Class
After saving, generate the DLL file.
This is the simplest DLL. The following is an example of calling this DLL.
Create a project and click "project" --> Add reference
Find the generated DLL and double-click it.
After adding a reference, nothing seems to happen. Then, we enter the following code:
Imports test. test
In this way, the DLL class is included.
Then we define a class
Dim test As New test. test
In this way, you can use the functions in it. The following is a program example.
Imports test. test
Public Class Form1
Private Sub Form1_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
Dim test As New test. test
MsgBox (test. test (1, 2 ))
End Sub
End Class
Run the program. You can see that the functions in the DLL are called.
This is the simplest DLL example. We can integrate some complex code into the DLL, which will be easier to upgrade or reuse later.