Win32 SDK编程之Windows编程开发基础知识

库最基本的使用 就是用来封装代码的。

3.3 静态库

静态库是以嵌入的方式在程序中或动态库中运行。

3.1 静态库的制作

1)新建一个静态库工程项目
在这里插入图片描述
2)直接下一步
在这里插入图片描述
3)选择应用程序类型为静态库
在这里插入图片描述
4)1.1在头文件夹目录中新建一个.h文件并插入如下代码:

#ifndef CALCULATION_H
#define CALCULATION_H

class Calculation
{
public:
	Calculation();
	int add(int a,int b);
	~Calculation();
};

#endif 

1.2在源文件夹目录中新建一个.cpp文件并插入如下代码:

#include "Calculation.h"

Calculation::Calculation()
{

}
int Calculation::add(int a,int b)
{
	return a + b;
}

Calculation::~Calculation()
{

}

3.2 静态库的使用

同制作静态库的流程大概一致,只需把应用程序类型选择为控制台应用程序即可。测试代码如下:

#include "Calculation.h"
#include <cstdio>
#include <Windows.h>

#pragma comment(lib,"staticLibrary.lib") //静态库所在的路径

int main()
{
	Calculation c; //定义一个Calculation类
	int ret = c.add(2,2); //使用Calculation中类的成员方法
	printf("%d\n",ret);

	system("pause");
	return 0;
}

测试结果如下:
在这里插入图片描述

3.3 总结

静态库程序的特点:

  1. 运行时不存在;
  2. 链接到可执行文件或动态库中;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值