VS2012创建动态库DLL(Win32)

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文件,运行出错:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值