凋用动态库
man.c 文件
#include <stdio.h>
#include <string.h>
#pragma comment(lib,"../max/Debug/max.lib")
// 注意这里是 dllimport
#define MAX_IMPORT __declspec(dllimport)
#define SUM_IMPORT __declspec(dllimport)
#define PLU_IMPORT __declspec(dllimport)
extern int MAX_IMPORT mymax(int a, int b);
extern int SUM_IMPORT sum(int a, int b);
extern int PLU_IMPORT plu(int a, int b);
int main()
{
printf("a+b=%d\n", sum(40, 20));
printf("a-b=%d\n", plu(40, 20 ));
printf("Max %d\n", mymax(40, 20 ));
return 0;
}
======================================================
man_dll.c文件
#include <stdio.h>
#include <string.h>
// 注意这里是 dllexport
#define MAX_EXPORT __declspec(dllexport)
#define SUM_EXPORT __declspec(dllexport)
#define PLU_EXPORT __declspec(dllexport)
int MAX_EXPORT mymax(int a, int b)
{
return (a<b)? b: a;
}
int SUM_EXPORT sum(int a, int b)
{
return (a+b);
}
int PLU_EXPORT plu(int a, int b)
{
return (a-b);
}
======================================================
把所生成的两个文件复制到man.c 文件下