dynamic link library (dll)
DESCRIPTION
Dynamic Link Library (DLL). Common frequently function Shared library Memory loaded Loaded once time 2 steps DLL programming Application programming. Dynamic Link Library (DLL). Dynamic Link Library (DLL) Example. Create DLL program for operate two integer numbers - PowerPoint PPT PresentationTRANSCRIPT
1
Dynamic Link Library (DLL)
Common frequently function Shared library Memory loaded
Loaded once time 2 steps
DLL programming Application programming
2
Dynamic Link Library (DLL)
3
Dynamic Link Library (DLL)Example
Create DLL program for operate two integer numbers Add(num1, num2), return num1+num2 Sub(num1, num2), return num1-num2 Mul(num1, num2), return num1*num2 Div(num1, num2), return num1/num2
Create application program to call DLL program
4
Part I: DLL programming1. Creating a Class Library (DLL) Create an Empty Class Libr
- - - -ary Project Select File >New >Project >Visual C# Projects >Class Library.
5
Class view
2. เพิ่��ม method ให้กั�บคลาส right click Class->Add ->Add method
6
กั�าห้นดค�าให้กั�บ method Add(Val1, Val2)
2. Add1. long
3. long
4. Val15.
Click
7
เพิ่��มตั�วแปรให้ครบสองตั�วด�งภาพิ่
finish
8
9
3. เพิ่��มค�าส��งในฟั�งกั ชั�น Add
public long Add(long Val1, long Val2){
return Val1 + Val2;}
10
4. เปล"�ยนชั$�อคลาสเป%น mcMathComp
public class mcMathComp {…
11
4. Build Project
Build Build Solution
ผลที่"�ไดจะไดไฟัล ที่"�เป%น DLL ภายใตัโฟัลเดอร \bin\debug
12
Part II: Application Programming1. Create New ProjectFileNew ProjectVisual C# ProjectWindows Application
13
2. Add Reference of the Namespace- Project >Add reference
14
วางปุ่��มบนฟอร์�ม
Browse
16
Brow to DLL file
17
3. กัารเร"ยกัใชังาน เพิ่��ม using mcMath ในส�วนที่"�ม"กัารเร"ยกัใชัด�งภาพิ่
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using mcMath;
namespace mcClient{
18
3. พิ่�มพิ่ Event on Click ของ Button1
private void radioButton1 _Click(object sender, System.EventArgse)
{ mcMathComcls= newmcMat hCom(); longlRes= cl s.Add( 55 , 45) ;
MessageBox.Show(lRes.ToString());}
19
Assignment
เข"ยนโปรแกัรมที่"�เป%น DLL 1 โปแกัรม เชั�น ที่�า operation ที่างคณิ�ตัศาสตัร เห้ม$อนกั�บตั�วอย�าง เปล"�ยนตั�วเลขเป%นกัารอ�านค�าเง�นแบบไที่ย เชั�น
String IntToBaht(100) จะไดค�าเป%น “ห้น/�งรอยบาที่ถ้วน”
เข"ยนโปรแกัรมเพิ่$�อที่�ากัารเร"ยกัใชังาน DLL ตั�วด�งกัล�าว http://www.c-sharpcorner.com/2/pr12
.asp