1. How to encapsulate your own DLL;
A. Open Visual Studio-file-New-project-class library-name Mytestdll;
B. Right key Class1.cs-modified to TestDll.cs;
C. write a function in it that you want to manipulate, such as:
public int Fnadd (int iAdd1, int iAdd2)
{
Return (IADD1 + iAdd2);
}
D. Save-build solution;
E. This is your debug folder there will be a MyTestDll.dll file, you can put it in the project you want to quote;
2. Use your own encapsulated DLL file;
A. Open Visual Studio-file-new-project-Windows Forms application-name Usemydll;
B. Yourself on the form, add three TextBox controls, and a button control;
C. Place the MyTestDll.dll file under the Debug folder;
D. References-Add references-browse-add MyTestDll.dll;
E. Double-click the Button1 event:
private void Button1_Click (object sender, EventArgs e)
{
Mytestdll.testdll M_testdll = new Mytestdll.testdll ();
int a = convert.toint16 (TextBox1.Text);
int b = convert.toint16 (TextBox2.Text);
TextBox3.Text = convert.tostring (M_testdll.fnadd (a,b));
}
F. Run the program to start the experiment;
Tip: 1. The emphasis is on this sentence: Mytestdll.testdll m_testdll = new Mytestdll.testdll ();
2.[dllimput ("kernel32")] is generally used to add a DLL library with the system itself;