DLL 函数导出和使用

DLL函数导出方式有多种方式,这里介绍的是其中一种方式

头文件:

#ifndef _GPTSQLITE_H__
#define _GPTSQLITE_H__

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _EXPORTING
#define CLASS_DECLSPEC __declspec(dllexport)
#else
#define CLASS_DECLSPEC __declspec(dllimport)
#endif

CLASS_DECLSPEC int Add(int i, int j);

#undef _DLL_GPTSQLITE

#ifdef __cplusplus
}
#endif

#endif

 源文件

#include "StdAfx.h"
#define _EXPORTING

#include "gptsqlite.h"

CLASS_DECLSPEC int Add(int i, int j)
{
	return i+j;
}

  调用函数

#include "stdafx.h"
#include<cstdlib>
#include <iostream>
#include "../dlldatabase/gptsqlite.h"
#pragma comment(lib, "dlldatabase.lib")
int _tmain(int argc, _TCHAR* argv[])
{
	int i = Add(1, 2);
	std::cout << i << std::endl;
	system ("pause");
	return 0;
}

  

posted @ 2012-03-04 22:16  小小亮FLY  阅读(390)  评论(0编辑  收藏  举报