?? usedll.cpp
字號:
//UseDll.cpp:顯式鏈接方式調(diào)用Dll
#include "iostream.h" //輸入輸出庫
#include "Windows.h"//使用API函數(shù)
typedef int (*PFNFactorial)(int); //宏定義FactorialFun函數(shù)指針類型
void main() //主函數(shù)
{
int n;
cout<<"本程序采用顯式鏈接的方式測試開發(fā)的Factorial DLL\n";
while(true) //循環(huán)計算
{
HINSTANCE hdll; //DLL的句柄
PFNFactorial facfun;//函數(shù)指針
hdll=LoadLibrary("..\\Factorial DLL.dll"); //LoadLibrary函數(shù)裝載DLL
if(hdll!=NULL)
{
//GetProcAddress函數(shù)獲得FactorialFun函數(shù)地址
facfun=(PFNFactorial)GetProcAddress(hdll,"FactorialFun");
}
cout<<"請輸入用于計算階乘的值:\n";
cin>>n; //等待用戶輸入
int result=facfun(n); //調(diào)用DLL函數(shù)進(jìn)行計算
cout<<"運算結(jié)果為:\n"<<result<<endl;
FreeLibrary(hdll); //釋放DLL
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -