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++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...
随机推荐
- jQuery源码分析学习--资料收集--更新中
1.逐行分析jQuery源码的奥秘 - 网易云课堂 http://study.163.com/course/courseMain.htm?courseId=465001#/courseDetail? ...
- eclipse使用异常An error has occurred.see error log for more details eclipse
eclipse使用异常An error has occurred.see error log for more details eclipse 解决Eclipse,MyEclipse出现An erro ...
- MySql cmd下的学习笔记 —— 有关多表查询的操作(多表查询练习题及union操作)
先建立一张 m 表 mysql> create table m ( -> mid int, -> hid int, -> gid int, ), -> matime da ...
- 【转载】论文笔记系列-Tree-CNN: A Deep Convolutional Neural Network for Lifelong Learning
一. 引出主题¶ 深度学习领域一直存在一个比较严重的问题——“灾难性遗忘”,即一旦使用新的数据集去训练已有的模型,该模型将会失去对原数据集识别的能力.为解决这一问题,本文提出了树卷积神经网络,通过先将 ...
- RVIZ 保存配置 and 使用配置
每次无参数启动RVIZ, 都会使用配置 -/.rviz/default.rviz 如果每次是正常退出的话,上一次的配置会被保存到文件-/.rviz/default.rviz 需要另外保存成配置文件的话 ...
- 【转】python f-string
[转]python f-string 文章目录 1. 主要内容 1.1. 旧时代的格式化字符串 1.1.1. Option #1: %-formatting 1.1.2. 怎样使用 %-forma ...
- eMMC基础技术9:分区管理
[转]http://www.wowotech.net/basic_tech/emmc_partitions.html 0.前言 eMMC 标准中,将内部的 Flash Memory 划分为 4 类区域 ...
- Windows PowerShell 入門(10)-デバッグ編
対象読者 Windows PowerShellでコマンドレット操作ができる方 何らかのプログラミング経験があればなお良い 必要環境 Windows PowerShell デバッグメッセージの出力 Po ...
- requests库入门09-OAUTH认证
实际登陆中,认证用到的token会变的,不过可以在GIthub设置一个私人token. 如图,登录GIthub,然后用户下面选择Settings/Developer settings/Personal ...
- [NOI2004]郁闷的出纳员(到底是谁郁闷啊?)
一道 FHQ treap 的裸水题,卡了这么久.(咦~一看就是修为不够) 题解什么的,不用看的(话说那我为什么要写这篇题解咧...),直接 FHQ 模板腾上去就能秒 A 了(打脸) 谈谈 de ...