DLL的使用
//[BCB中的宣告 *.dll]
extern "C" __declspec(dllexport) __stdcall int Myfunction_Add(int x,int y)
{
int z = x + y;
return z;
}
extern "C" __declspec(dllexport) __stdcall int Myfunction_Add(int x,int y)
{
int z = x + y;
return z;
}
[BCB 動態載入]
int (*Myfunction_Add)(int,int);
HINSTANCE hInst=LoadLibrary("my.dll");
if (hInst == NULL)
{
ShowMessage("Null");
}
HINSTANCE hInst=LoadLibrary("my.dll");
if (hInst == NULL)
{
ShowMessage("Null");
}
(FARPROC &) Myfunction_Add = GetProcAddress(hInst, "Myfunction_Add");
int c = Myfunction_Add(10,20);
ShowMessage(c);
FreeLibrary(hInst);
int c = Myfunction_Add(10,20);
ShowMessage(c);
FreeLibrary(hInst);
[C# 引用]
//載入 + 宣告
[DllImport("d:\\my.dll")]
public static extern int Myfunction_Add(int x,int y);
//使用
int c = Myfunction_Add(10,20);
MessageBox.Show(c.ToString());
int c = Myfunction_Add(10,20);
MessageBox.Show(c.ToString());
留言
張貼留言