在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. Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project

    Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project Qt WebKit and HTML5 geolocation   I ...

  2. 查找jar包的站点

    1.findJAR.com: http://www.findjar.com/index.x 2.jarfire:  https://cn.jarfire.org/

  3. Android API 中文(77)——AdapterView.OnItemSelectedListener

    前言 本章内容是android.widget.AdapterView.OnItemSelectedListener,版本为Android 2.3 r1,翻译来自"cnmahj",欢 ...

  4. js中new构造函数的研究

    <javascript高级编程>里对new操作符的解释: new操作符会让构造函数产生如下变化: 1.       创建一个新对象: 2.       将构造函数的作用域赋给新对象(因此t ...

  5. mysql 中的 IF 和 IFNULL 用法

    IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境. IF(S ...

  6. 电信光纤猫 f412超级密码

    中兴F412光猫超级密码破解.破解用户限制.关闭远程控制.恢复路由器拨号 http://bbs.mydigit.cn/simple/?t1021161.html 不少家庭都改了光纤入户,那肯定少不了光 ...

  7. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

  8. Servlet转发和重定向的区别

    附上视频教学的一张图: 区别: 1.转发产生一次请求,一次响应: 重定向产生2次请求 两次响应 2.转发客户端不可见的: 重定向客户端是可以察觉的. 3.转发时候url不变: 重定向URL会改变 案例 ...

  9. Web APIs 基于令牌TOKEN验证的实现

    Web APIs 基于令牌TOKEN验证的实现 概述: ASP.NET Web API 的好用使用过的都知道,没有复杂的配置文件,一个简单的ApiController加上需要的Action就能工作.但 ...

  10. grawlew 编译

    http://somefuture.iteye.com/blog/2002052 Gradlew behind a proxy systemProp.http.proxyHost=www.someho ...