Create a Class Library (.dll) and link to Main Application using Early Binding or Late Binding.
Howto
1. Create class library File :
- New Project > Class Library ( give name TestDLL, it will use as namespace)
- create simple class like this :
Imports System.Windows.Forms 'import this class , you will need any method
Public Class Myclass
Public Sub MyMethod()
MessageBox.Show("Hello World DLL")
End Sub
End Class
save project and then Build > Build TestDLL , you can find the file TestDLL.dll at folder bin/release/
2. Create Main Application
- New Project > Windows Form Application (give name MyForm)
- to use Class Library , we have 2 method : Early Binding and Late Binding
- Early binding means , we load the dll resource when Main Application Run , it will increase perfomance (speed) when access the Dll.
- Late Binding means , we load the dll resource as we need so we use the memory as needed too.
* Early Binding
- to use early binding just Project > Add Preference > find TestDLL.dll
- Import the namespace after add refference : import TestDLL
- Dll are now linked , you can create an object now.
Dim obj = New Myclass()
obj.MyMethod()
* Late Binding
- Late Binding we don't use refference , but we need the path of file dll. don't forget to drop the dll files into 1 folder with Main Application.
- Linking to DLL
'Dim RefAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom("Filename.dll")
Dim RefAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom("TestDLL.dll")
'Dim obj As Object = RefAssembly.CreateInstance("Namespace.Class", IgnoreCase)
Dim obj As Object = RefAssembly.CreateInstance("TestDLL.Myclass", True)
obj.MyMethod()
Simple right ? hope it's help you :D
Post a Comment
Harap gunakan bahasa yang baik dan sopan, terima kasih