在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获取系统配置文件的配置参数的更多相关文章

  1. C/C++ Windows API——获取系统指定目录(转)

    原文地址:C/C++ Windows API——获取系统指定目录 经测试,在win10 VS2017中用wprintf()输出正常,SHGetSpecialFolderPath函数也正常运行 但是用M ...

  2. 调用windows api 获取系统分辨率

    c++中: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_CY ...

  3. C/C++ Windows API——获取计算机信息 转

    转自:http://blog.csdn.net/chy555chy/article 函数 头文件 作用 GetVersionEx <windows.h> 获取系统版本信息(deprecat ...

  4. C# API 获取系统DPI缩放倍数跟分辨率大小

    原文:C# API 获取系统DPI缩放倍数跟分辨率大小 using System; using System.Drawing; using System.Runtime.InteropServices ...

  5. windows API 创建系统托盘图标

    系统托盘在我们使用的程序中很普遍,下面我们来看一个很不错的例子,使用Win32 API实现,对理解系统托盘有些帮助. [cpp] view plaincopy #include <windows ...

  6. 使用Windows api 获得系统时间并生成文件夹

    // 使用window api 获得系统时间 // 生成 #include "stdafx.h" #include <Windows.h> #include <d ...

  7. windows server 2008系统VPN服务配置

    转自:http://www.softxp.net/article/win2008-vpn/,,仅作自己的笔记用 Windows sever 2008 R2的NPS(network policy ser ...

  8. [windows API]获取当前系统图标,文字大小

     取DPI 缩放比例 HWND wnd = ::GetDesktopWindow(); dbg_print("desktopwnd:0x%X\n",wnd); HDC dc = G ...

  9. windows API 统计系统字体

    最近工作中遇到一个需求,需要统计当前系统中包含的所有字体.在网上逛了一圈后发现了EnumFontFamiliesEx这个API好像就可以实现这个功能.这里将自己对这个API的理解做一个记录,算是对这块 ...

随机推荐

  1. HDOJ 1043 Eight(A* 搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 思路分析: <1> 搜索算法: A*算法, Heuristic函数:曼哈顿距离 &l ...

  2. iOS键盘遮挡问题解决办法

    iOS开发之“键盘遮挡输入框的解决办法”之一 -----键盘通知之前处理这种问题,总是在触发输入框编辑事件键盘弹出的时候,将当前的View整体向上移动,结束编辑又整体向下移,耗时耗力效率低. 在网上看 ...

  3. exists

    select count(*) from Table_A where exists (select count(*) from Table_B.Column1 = Table_A.Column1) 该 ...

  4. 「OC」 封装

    一.面向对象和封装 面向对象的三大特性:封装.继承和多态 在OC语言中,使用@interface和@implementation来处理类.   @interface就好像暴露在外面的时钟表面,像外界提 ...

  5. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  6. [LeetCode]题解(python):017-Letter Combinations of a Phone Number

    题目来源: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 题意分析: 这道题是输入一段数字字符digits, ...

  7. python--help

    python help 学习python的过程中,难免遇到一些生疏的东西,为此需要参看相关的文档说明. Linux下众所周知有man可以查找系统的命令帮助页:对于python也提供了自己的帮助文档的2 ...

  8. Ubuntu基本设置

    (1)  为了启用 root 帐号 (也就是 设置一个口令) 使用: sudo passwd root 1.设置IP, 终端输入 sudo gedit /etc/network/interfaces ...

  9. TabSpec和TabHost实例

    TabSpec与TabHost TabHost相当于浏览器中浏览器分布的集合,而Tabspec则相当于浏览器中的每一个分页面.d在Android中,每一个TabSpec分布可以是一个组件,也可以是一个 ...

  10. 我在北京找工作(二):java实现算法<1> 冒泡排序+直接选择排序

    工作.工作.找工作.经过1个多星期的思想斗争还是决定了找JAVA方面的工作,因为好像能比PHP的工资高点.呵呵 :-)  (其实我这是笑脸,什么QQ输入法,模拟表情都没有,忒不人性化了.) 言归正传, ...