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的理解做一个记录,算是对这块 ...
随机推荐
- 外网訪问内网应用实现之无公网IP、多port、固定port、UDP等应用的实现方法
有公网IP时,能够通过路由映射来实现外网訪问内网.然,当没有公网IP时,怎样实现外网訪问内网应用? 硬件路由方法因为无公网不可行,能够使用软件port映射的方法.如开放的NAT123全port映射. ...
- 【ActiveMQ】设置自动重连
<property name="brokerURL" value="tcp://localhost:61616"/> <property na ...
- spring和mybatis整合进行事务管理
1.声明式实现事务管理 XML命名空间定义,定义用于事务支持的tx命名空间和AOP支持的aop命名空间: <beans xmlns="http://www.springframewor ...
- jQuery+Ajax+Jsp做二级级联
终于弄懂了这个级联,我去!必须得在博客记下来. 1, JS代码: $(document).ready(function(){ $("#select1").change(functi ...
- VMware: linux起步提示 memory for crashkernel(0*0 to 0*0)not within permissible
(virtualbox/VMware)linux起步提示memoryforcrashkernel(0*0 to 0*0)notwithinpermissible http://www.myexcep ...
- 浅谈Linux ftp服务器相关配置
首先我们需要在Linux系统下安装FTP服务器 Ubuntu sudo apt-get install....... centos yun....... 然后,我们要配置vsftpd.conf文件 ...
- qemu核心机制分析-协程coroutine
关于协程coroutine前面的文章已经介绍过了,本文总结对qemu中coroutine机制的分析,qemu 协程coroutine基于:setcontext函数族以及函数间跳转函数siglongjm ...
- 解决ASP.NET回传后div滚动条位置复位的问题
中心思想:用一个隐藏控件保存当前scorll值.回传回来后根据scrollTop的值,然后在Page_Load中重新设置scrollTop. 首先是为DIV添加一个 onscroll="ja ...
- cpu有哪些架构
原文:http://blog.csdn.net/wyzxg/article/details/5027738 author:skatetime:2009/12/17 这几天在下载RPM包的时候,总会看见 ...
- Xamarin.Android开发实践(四)
原文:Xamarin.Android开发实践(四) Xamarin.Android下获取与解析JSON 一.新建项目 1.新建一个Android项目,并命名为为NetJsonList 2.右击引用,选 ...