-
函數封裝
鎖定
- 中文名
- 函數封裝
- 所屬學科
- 數學
C語言函數封裝例子
func1(.....)
{
.....
.....
}
func2(......)
{
.....
.....
}
func3(.....)
{
func1(....)
{
func2(...)
{
}
}
能不能將func1和func2封裝成一個DLL,能夠直接讓func3調用?
當然可以,寫一個DLL就可以了,把fun1和fun2寫進去,舉個例子:
在DLL中寫入:
//MyDll.h
extern "C" int _declspec(dllexport) Max(int a, int b);
//MyDll.cpp
#include "windows.h"
#include "MyDll.h"
int Max(int a, int b)
{
if(a>=b)return a;
else return b;
}
在console應用程序中寫入:
#include "stdio.h"
#include "stdlib.h"
extern "C" _declspec(dllexport)
int Max(int a, int b);
#pragma comment(lib,"MyDll.lib")
int main()
{
int a;
a = Max(10, 5);
printf("%d \n", a);
return 0;
}
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:13次歷史版本
- 最近更新: 北辰以北1209