vs2010下编译DLL库和使用

一、创建DLL 文件

1 vs2010下选择win32应用程序,创建DLL 工程

2 创建头文件testdll.h

#ifndef TestDll_H_
#define TestDll_H_
#ifdef MYLIBDLL
#define MYLIBDLL extern "C" _declspec(dllimport) 
#else
#define MYLIBDLL extern "C" _declspec(dllexport) 
#endif
MYLIBDLL int Add(int plus1, int plus2);
//You can also write like this:
//extern "C" {
//_declspec(dllexport) int Add(int plus1, int plus2);
//};
#endif

3 创建源文件

#include "stdafx.h"

#include "testdll.h"
#include <iostream>
using namespace std;
int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}
4 创建模块文件

LIBRARY "MyDLL"
EXPORTS
Add @1
5 选择release版本进行编译

二、调用DLL文件中的函数

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>

#pragma comment (lib , "MyDll.lib" )

extern "C"_declspec (dllimport) int Add(int plus1, int plus2);

int _tmain(int argc, _TCHAR* argv[])
{
	
	printf("%d\n",Add(6,4));

	return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值