Windows API获取系统配置文件的配置参数
在Windows平台下获取系统配置文件(如:System.ini)的配置参数。
系统配置文件System.ini的内容如下:
[SYSTEM]
ServiceIP = 10.128.11.99:60000
CommuType = ShareMemory
代码如下:
包含头文件 Winbase.h (include Windows.h)
//GetCurrentPath()函数获取可执行模块的全路径,并将路径中的"\\"变为‘\’,之后去掉了路径中的可执行文件的名字
static void GetCurrentPath(char *PathName)
{
char *p,*q;
GetModuleFileName(NULL,PathName,256);
q = PathName;
do
{
p = q+1;
q = strstr(p,"\\");
} while (q);
if (p) *p = 0;
p = strstr(PathName,":");
if (p)
{
if (p - PathName > 1)
{
q = PathName;
p--;
do
{
*q++ = *p++;
} while(*p != 0);
*q = 0;
}
}
}
//GetSystemConfig()获取System字段下,键为strKeyName对应的值,如果没有获取到,则以默认值strDefault填充。
void GetSystemConfig( string strKeyName,string strDefault,char *szReciBuff,int nLen )
{
char szFileName[256];
GetCurrentPath(szFileName);
strcat(szFileName,"System.ini");
GetPrivateProfileString("SYSTEM",strKeyName.c_str(),strDefault.c_str(),szReciBuff,nLen,szFileName);
}
//GetSystemIPConfig()获取系统文件中ServiceIP键的值
void GetSystemIPConfig( char *szReciBuff,int nLen )
{
string strDefaultV="127.0.0.1:60000";
GetSystemConfig("ServiceIP",strDefaultV,szReciBuff,nLen);
}
//GetSystemCommTypeConfig()获取系统文件中ShareMemory键的值
void GetSystemCommTypeConfig( char *szReciBuff,int nLen )
{
string strDefaultV="ShareMemory";
GetSystemConfig("CommuType",strDefaultV,szReciBuff,nLen);
}
//测试代码:
int main()
{
char szCommuType[256]="";
GetSystemCommTypeConfig(szCommuType,256);
GetSystemIPConfig(szCommuType,256);
}
Windows API获取系统配置文件的配置参数的更多相关文章
- C/C++ Windows API——获取系统指定目录(转)
原文地址:C/C++ Windows API——获取系统指定目录 经测试,在win10 VS2017中用wprintf()输出正常,SHGetSpecialFolderPath函数也正常运行 但是用M ...
- 调用windows api 获取系统分辨率
c++中: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_CY ...
- C/C++ Windows API——获取计算机信息 转
转自:http://blog.csdn.net/chy555chy/article 函数 头文件 作用 GetVersionEx <windows.h> 获取系统版本信息(deprecat ...
- C# API 获取系统DPI缩放倍数跟分辨率大小
原文:C# API 获取系统DPI缩放倍数跟分辨率大小 using System; using System.Drawing; using System.Runtime.InteropServices ...
- windows API 创建系统托盘图标
系统托盘在我们使用的程序中很普遍,下面我们来看一个很不错的例子,使用Win32 API实现,对理解系统托盘有些帮助. [cpp] view plaincopy #include <windows ...
- 使用Windows api 获得系统时间并生成文件夹
// 使用window api 获得系统时间 // 生成 #include "stdafx.h" #include <Windows.h> #include <d ...
- windows server 2008系统VPN服务配置
转自:http://www.softxp.net/article/win2008-vpn/,,仅作自己的笔记用 Windows sever 2008 R2的NPS(network policy ser ...
- [windows API]获取当前系统图标,文字大小
取DPI 缩放比例 HWND wnd = ::GetDesktopWindow(); dbg_print("desktopwnd:0x%X\n",wnd); HDC dc = G ...
- windows API 统计系统字体
最近工作中遇到一个需求,需要统计当前系统中包含的所有字体.在网上逛了一圈后发现了EnumFontFamiliesEx这个API好像就可以实现这个功能.这里将自己对这个API的理解做一个记录,算是对这块 ...
随机推荐
- flexjson 的使用
日期转换 JSONSerializer serializer = new JSONSerializer(); serializer.exclude(new St ...
- Bitmap recycle()
Bitmap调用recycle? When? Bitmap有一个recycle方法,意思非常easy,回收Bitmap的空间. Q 1: Bitmap是否有调用recycle方法的必要性? A: 嵌入 ...
- 谁动了我的CurrentPrincipal?解释一下为什么CurrentPrincipal变了,并解决这个问题。
在上一篇博客中我遇到了一个问题,并且导致了我无法继续进行授权和验证.经过查阅资料和解决另外一个问题的过程,我突然想通了为什么CurrentPrincipal变了.并且经过验证后的确是我所理解的那样.下 ...
- ie调试控制台
function initConsole() { var console = document.createElement('div'); console.id = 'errorConsole'; d ...
- asp.net连接ORACLE数据库
这段时间维护客户的一个系统,该系统使用的是ORACLE数据库,之前开发的时候用的都是MSSQL,并没有使用过ORACLE.这两种数据库虽然都是关系型数据库,但是具体的操作大有不同,这里作下记录. 连接 ...
- ADO.NET(一) 空间 ADO.NET结构 命名空间(车延禄) System.Data—— 所有的一般数据访问类 S(转载)
ADO.NET(一) 空间 ADO.NET结构 命名空间(车延禄)System.Data—— 所有的一般数据访问类System.Data.Common—— 各个数据提供程序共享(或重写)的类Sys ...
- 通过SqlHelper实现登录
1.建立解决方案:. 首先创建windows窗体应用程序,然后拖出登录界面 2. 写配置文件App.config: <configuration> <conn ...
- Java之对象序列化和反序列化
一.对象序列化和反序列化存在的意义: 当你创建对象,只要你需要,他就一直存在,但当程序结束,对象就会消失,但是存在某种情况,如何让程序在不允许的状态,仍然保持该对象的信息.并在下次程序运行的时候使用该 ...
- Codeforces 18C C. Stripe
Codeforces 18C C. Stripe 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E 题 ...
- js基础之冒号
js中冒号的作用有两种, 转自:http://www.kqiqi.com/knowledge/web-based/506.html 一.?: 操作符 a = expression ? b : c;如果 ...