1、创建一个项目:
2、添加一个类:
MyMath.h
#pragma once
#include "dynamic_lib.h"
class DYNAMIC_LIB_API MyMath
{
public:
MyMath(void);
~MyMath(void);
int Add(int a, int b);
};
MyMath.cpp
#include "stdafx.h"
#include "MyMath.h"
MyMath::MyMath(void)
{
}
MyMath::~MyMath(void)
{
}
int MyMath::Add(int a, int b)
{
return a + b;
}
3、生成:
4、创建一个测试项目:
5、显式引用:
// dynamic_lib_test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "../dynamic_lib/MyMath.h"
#pragma comment(lib, "../Debug/dynamic_lib.lib")
int _tmain(int argc, _TCHAR* argv[])
{
MyMath myMath;
int a = myMath.Add(6, 4);
int b = fndynamic_lib();
int c = ndynamic_lib;
printf("%d %d %d\n", a, b, c);
return 0;
}
6、运行如下:
7、两个项目的生成文件:
8、删除.dll文件,运行出错: