调用类的动态连接库示例1
来源:互联网 发布:公安大数据应用案例 编辑:程序博客网 时间:2024/06/05 21:03
在test3工程下建立两个类point和circle类如下:
point类,声明可以被外面所调用
point.h
#ifndef POINT_H
#define POINT_H
#ifdef DLL_FILE
class _declspec(dllexport) point
#else
class _declspec(dllimport) point
#endif
{
public:
float x;
float y;
point();
point(float x_coordinate,float y_coordinate);
};
#endif
point.cpp
#ifndef DLL_FILE
#define DLL_FILE
#endif
#include "point.h"
point::point()
{
x= 0.0;
y= 0.0;
}
point::point(float x_coordinate,float y_coordinate)
{
x = x_coordinate;
y = y_coordinate;
}
circle类
circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "point.h"
#ifdef DLL_FILE
class _declspec(dllexport) circle
#else
class _declspec(dllimport) circle
#endif
{
public:
void SetCentre(const point circlepoint);
void SetRadius(float r);
float GetGirth();
float GetArea();
circle();
private:
float radius;
point centre; //对象
};
#endif
circle.cpp
#ifndef DLL_FILE
#define DLL_FILE
#endif
#include "circle.h"
#define PI 3.1415926
circle::circle()
{
centre = point(0,0);
radius = 0;
}
float circle::GetArea()
{
return PI*radius*radius;
}
float circle::GetGirth()
{
return 2*PI*radius;
}
void circle::SetCentre(const point circlepoint)
{
centre= circlepoint;
}
void circle::SetRadius(float r)
{
radius = r;
}
其中point和circle类在同一个工程下,circle可以使用point类的函数。这两个类都要声明成被外面所以用的类,其中circlr类直接会被调用函数所调用
编译后澡debug下会生成test3.dll和test.3lib文件
调用函数:
#include "D:\\gongzuo_test\\test3\\circle.h" //包含类声明头文件
#pragma comment (lib,"test3.lib");
#include <stdio.h>
int main()
{
circle c;
point p(2.0,2.0);
c.SetCentre(p);
c.SetRadius(1.0);
printf("area:%f",c.GetArea(),c.GetGirth());
return 0;
}
调用函数一定家加上ciecle类的头文件(全路径的),声明调用那个lib文件,注意:一定要把test3的lib文件和dll文件放到调用函数的目录下,否则报错。
- 调用类的动态连接库示例1
- DLL专题之动态连接库的静态调用(1)
- 动态连接库的创建及调用
- C++动态连接库调用
- 动态库调用静态库示例讲解
- Linux JNI调用so动态库示例
- python调用c语言动态库示例
- 动态调用WCF示例
- python调用的动态连接库的方法(ctypes)
- TT 调用动态连接库的函数的方法
- java怎样调用vb编写的动态连接库
- vb调用VC动态连接库的总结
- 动态连接库的建立与调用(基础)
- DLL专题之动态连接库的静态调用(2)
- 动态连接库的建立与调用(基础)
- 在存储过程中调用外部的动态连接库
- 在存储过程中调用外部的动态连接库
- PB动态连接库与外部函数的调用
- 新一代脚本语言引擎Cx -- 应用之AutoCAD二次开发 (2)
- pthread_detach
- C#String类与StringBuilder类的区别
- 什么样的书能流传很久
- 虚拟系统安装VMtools
- 调用类的动态连接库示例1
- linux 下的讯雷 axel
- flash actionscript3.0 beginGradientFill渐变填充 水晶按钮制作
- 终于拿到debugman的邀请码了
- 命令模式(封装调用)
- 分享编译Android源码的全过程
- .net 多线程详细总结
- 拼写检查的Lucene源码分析
- Pycrc教程(自动生成C语言的CRC代码工具)