C++ GetSystemDirectory()
关于GetSystemDirectory function,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724373(v=vs.85).aspx
以下代码摘自Getting System Information(https://msdn.microsoft.com/en-us/library/windows/desktop/ms724426(v=vs.85).aspx)。
IDE: Microsoft Visual Studio Community 2017 15.5.2
操作系统:Windows 7 x64
#include "stdafx.h" /* IDE自行创建的 */ #include <windows.h> #define INFO_BUFFER_SIZE 21 int main(int argc, char **argv)
{
TCHAR infoBuf[INFO_BUFFER_SIZE];
UINT RetSize; RetSize = GetSystemDirectory(infoBuf, INFO_BUFFER_SIZE);
// RetSize = 0;
if ((RetSize != ) && (RetSize <= INFO_BUFFER_SIZE)) {
// If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer,
// not including the terminating null character. // Display the system directory.
printf("System Directory: %ls", infoBuf);
}
else if (RetSize > INFO_BUFFER_SIZE) {
// If the length is greater than the size of the buffer,
// the returnv alue is the size of the buffer required to hold the path,
// including the terminating null character.
printf("The size of the buffer is not enough, need %d TCHARs at least. \n", RetSize);
}
else {
// If the function fails, the return value is zero. To get extended error information, call GetLastError.
printf("Get system directory failed with error: %d", GetLastError());
} getchar(); return ;
}
可以修改INFO_BUFFER_SIZE的值,改变程序的运行结果。
也可以去掉RetSize = 0;前面的注释,模拟错误(实际上不是错误,我只是用来测试if语句的条件)。
不知道是否存在BUG???
C++ GetSystemDirectory()的更多相关文章
- GetWindowsDirectoryA and GetSystemDirectory
#include <iostream> #include <Windows.h> using std::cout; using std::endl; // 获取Windows文 ...
- C# Windows API
API:应用程序接口(API:Application Program Interface)应用程序接口(API:application programming interface)是一组定义.程序及协 ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- asp.net mvc4 简单的服务器监控开发之C#获取服务器CPU、RAM、TCP等系统信息(上)
一.背景 前段时间服务器出了点问题,加上学业愈来愈紧张,写博文分享的时间越来越少.虽然不是第一次在博客园上写经验,但是近期分享的博文得到了不少的朋友支持和指正,在这里内心非常感激和开心.希望以后能认真 ...
- C语言操作注册表 写入 读取信息
#include <stdio.h>#include <windows.h>int main(void){char regname[]="Software\\Micr ...
- 转:Delphi 6 实用函数
来自: daocaoren0824, 时间: -- ::, ID: 再给你一份 程序员实用函数 {▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎} {▎ ▎} {▎ 大 ...
- DELPHI实现关闭指定进程,自身防杀
偶然翻到很久以前用DELPHI写的一个小程序,实现功能是在后台默默关闭符合条件的进程,并隐藏自身.编写目的是为了防止办公电脑运行游戏. 实现原理是: 1.程序运行后将自身以不同的名称一式三份存到系统各 ...
- C#:获取环境信息
外部环境数据1.需要管理员权限2.需要安装office2003以上完整版3.需要安装flash reader 10.0以上4.需要安装adodb reader;Adobe Acrobat X Pro; ...
- WinPipe后门程序代码示例(仅限技术交流)
具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...
随机推荐
- mysql 查询优化 ~ select count 知多少
一 简介:今天咱们来聊聊mysql的查询总数 二 具体介绍 1 从引擎层面说 myisam myisam的扫描总行数是非常快的,这是因为myisam会将表的总行数存储起来,定期维护,但是注意,一旦加 ...
- pwnable.kr fb
fb-1 pt 连接到服务器,发现 有三个文件,fd脚本,fd.c脚本的源程序,flag是要看的东西,无权限 来我们分析一下源码 如果只传进去一个值,print” pass argv[1] a num ...
- 20165237 2017-2018-2 《Java程序设计》第9周学习总结
20165237 2017-2018-2 <Java程序设计>第9周学习总结 教材学习内容总结 1.URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符(Un ...
- nginx 模块配置
第一个 当前活跃的连接数 nginx握手的数 连接数 总的请求数
- EM算法(坐标上升算法)
原文地址:https://www.cnblogs.com/to-creat/p/6075322.html 机器学习十大算法之一:EM算法.能评得上十大之一,让人听起来觉得挺NB的.什么是NB啊,我们一 ...
- 【转】python模块分析之unittest测试(五)
[转]python模块分析之unittest测试(五) 系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块分析之typing(三) p ...
- Eclipse下egit插件的使用
接触GIT已经很久了,但碰到的公司一直都在使用SVN,并因为各种理由拒绝换成GIT.今年换了份工作,乘着搭建公司新框架和项目的机会,总算在正式项目上使用了GIT.GIT的服务器直接就用了https:/ ...
- 在VS解决方案资源管理器中自动定位当前编辑中的文件
依次点击 [工具]- [选项] - [项目和解决方案]-[常规]- 勾选[在解决方案资源管理器中跟踪活动项]
- docker拉取镜像报错:net/http: TLS handshake timeout.
docker拉取镜像报错:net/http: TLS handshake timeout. 启动一个后台的busybox容器 [yunva@node1 network-scripts]$ docker ...
- appium常用方法
1.输入中文 在capabilities中增加两项设置: capabilities.setCapability("unicodeKeyboard", "True" ...