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;
}