库地址:
GitHub - liwengithub/WinLib: Windows Api Enclosing C++ Library
还在天天翻MSDN看API参数吗,还在无数次的造轮子吗,还在一个项目里面看见各种版本的封装库吗,还在天天和同事撕逼吗,还在加班调试自己写的BUG吗。
有了这个库,一切烦恼皆没有,6点下班。
包含操作系统相关、网络、进程、文件、内存、字符串等常见winapi封装。
一些代码演示:
———————————————————————————————————————————————
#include "WinLibOs.h"
//系统是否是X64
WinLib::OsIs64()
//当前用户名
tcout << _T("CurrentUserName:") << WinLib::OsCurrentUserName() << std::endl;
//当前机器名
tcout << _T("PcName:") << WinLib::OsPcName() << std::endl;
//CPU核心数
tcout << _T("CPUCount:") << WinLib::OsGetCPUCount() << std::endl;
//内存大小
tcout << _T("MemoryMb:") << WinLib::OsGetMemoryMb() << std::endl;
//屏幕分辨率
WinLib::OsGetScreenResolution(x, y);
//枚举磁盘
std::vector<tstring> LogicalDriveNames;
WinLib::OsEnumLogicalDriveName(LogicalDriveNames);
//关闭系统重定向功能 让X86进程可以读写C:\Windows\System32
PVOID OldValue = 0;
//WinLib::OsDisableFileRedirection(OldValue);
//WinLib::OsEnableFileRedirection(OldValue);
//系统版本号
DWORD MajorVer, MinorVer, BuildNumber;
WinLib::OsVersionNumber(MajorVer, MinorVer, BuildNumber);
std::string OsVer = "unknown";
if (MajorVer == 10)
{
OsVer = "Windows 10";
if (BuildNumber >= 22000)
{
OsVer = "Windows 11";
}
}
else if (MajorVer == 6 && MinorVer == 3)
{
OsVer = "Windows 8.1";
}
//...
std::cout << "OsVer:" << OsVer << std::endl;
———————————————————————————————————————————————————————
#include "WinLibSe.h"
//设置文件所有者
WinLib::SeTakeFileOwnership(WinLib::OsCurrentUserName(), _T("d:\\test.exe"));
//获取文件权限
WinLib::SeSetFileAllowAccess(WinLib::OsCurrentUserName(), _T("d:\\test.exe"));
———————————————————————————————————————————————————————
#include "WinLibFs.h"
//获取文件大小
tstring FilePath = WinLib::OsGetWindowsDirectory() + _T("\\explorer.exe");
DWORD Size = WinLib::FsGetFileSize(FilePath);
tcout << FilePath << _T(" Size:") << Size << std::endl;
//获取文件大小 超过4GB
DWORD64 Size2 = WinLib::FsGetFileSize64(FilePath);
tcout << FilePath << _T(" Size:") << Size2 << std::endl;
//文件是否存在
WinLib::FsIsFile(_T("c:\\windows\\notepad.exe"));
//目录是否存在
WinLib::FsIsDirectory(_T("c:\\windows"));
//写文件
WinLib::FsWriteFileData(_T("d:\\1.txt"), "txt&#