C++ 调用C++写的类库的2种方法之一(隐式链接)

一:创建C++ DLL类库,名称:Dll1

1.Dll1.h

/*#ifndef Dll_API
#else
#define Dll_API _declspec(dllimport)
#endif

*/
#include "stdafx.h"

class _declspec(dllexport) Point
{
public:
	int output(int x,int y);

};

  2.Dll1.cpp

// Dll1.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
#include"Dll1.h"
#include "iostream"
using namespace std;

int Point::output(int x,int y)
{
 return (x+y);

};

  二:C++启动项目win32项目,名称:CeshiDllClass

1.CeshiDllClass.h

#include "stdafx.h"
 class  _declspec(dllimport) Point
{
public:
	int output(int x,int y);

};

2.CeshiDllClass.cpp

// CeshiDllClass.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "CeshiDllClass.h"
//#include "E:\visual studio 2008\project\CeshiDllClass\Dll1\Dll1.h"
#include<iostream>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	Point a;
	
	cout<<a.output(1,2)<<endl;
	return 0;
}

三:配置

     1.想将dll文件copy到启动项目的debug中去。

     2。按照下图中的红框来设置。我不明白我的为什么要在这里加引用,如果不加,它就会报错,解析不了,网上的都没有加,所以在这里碰到了很多的挫折。

3. 结果

     在dos命令窗口出现1+2的结果 3

这都是测试用的数据,所以就简单的用了下加法运算。如有疑问请给我联系。

 

 

posted @ 2013-11-17 22:07  nanyangzp  阅读(570)  评论(0)    收藏  举报