创建和使用DLL动态库

来源:互联网 发布:direct是什么软件 编辑:程序博客网 时间:2024/05/17 02:24

一.创建DLL项目

1. 新建立项目 选择控制台程序, DLL

2. 创建test.h  test.cpp 文件
//test.h
#pragma once

__declspec(dllexport) int TestAdd(int a, int b);

//test.cpp
#include "stdafx.h"
#include "test.h"

int TestAdd(int a, int b)
{
return a+b;
}

3.编译会生产 lib和dll文件.

二.使用dll项目

1. 新建立使用Dll的项目
2. 将 test.h lib dll 复制到项目文件中
3. 使用dll中的接口
#include "stdafx.h"
#include "test.h"
#pragma comment(lib,"MyMath.lib")

int _tmain(int argc, _TCHAR* argv[])
{
int a=3;
int b=4;
int c=TestAdd(a,b);
return 0;
}