DLL的编写方法

来源:互联网 发布:js数组去掉空格 编辑:程序博客网 时间:2024/05/18 02:07

以add()函数为例:

一、建testdll

1、在头文件testdll.h中:

#ifdef dll_API#else #define dll_API extern "C" _declspec(dllimport)#endifdll_API int add(int a,int b);


2、在testdll.cpp文件中

#include "stdafx.h"#define dll_API extern "C" _declspec(dllexport);#include "dll.h"#include<iostream>int add(int a,int b){printf("dll中函数被调用!");return a+b;}


二、使用dll:(静态加载的方法,动态加载看另一篇文章http://blog.csdn.net/u013394782/article/details/24925077)

1、将建testdll时生成的testdll.dll,testdll.lib (这俩在第一个debug下),testdll.h文件拷贝到 调用程序的目录下(第二个debug所在的目录下);

2、调用程序中:项目\属性\配置属性\连接器\输入\附加依赖项  中写入 testdll.lib;

3、在调用程序的.cpp文件中,加入头文件 #include"testdll.h"


0 0
原创粉丝点击