Windows API获取系统配置文件的配置参数
来源:互联网 发布:python np.split 编辑:程序博客网 时间:2024/05/17 01:07
在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获取系统配置文件的配置参数
- SystemParametersinfo系统配置的获取
- ubuntu 的系统配置文件
- 使用API获取Windows系统的文件关联图标
- 使用Windows API保存配置参数
- 查看windows系统配置的方法
- 读取配置参数的properties文件,路径获取完美解决
- 读取配置参数的properties文件,路径获取完美解决
- 把系统配置写入文件做文件配置
- iphone开发--获取系统配置文件内容
- 【C#】系统配置文件的读写
- Linux环境的系统配置文件
- 突变:mongoose-os的系统配置API改变
- 配置BASH SHELL和系统配置文件
- 《Windows API》文件的复制
- jsp获取配置.propertiesd文件中的参数
- Windows API的参数及返回值
- 获取系统信息的有关Windows API
- 【盘点linux硬盘加载挂载的方法】
- android 修改已建工程的API版本
- 关于网赚
- netstat命令详解
- flex操作XML,强力总结帖
- Windows API获取系统配置文件的配置参数
- Ubuntu 批量更改文件内容
- Ubuntu下,grep的用法
- 各浏览器模拟手机浏览器的方法
- VS2008操作Word2007 2010保存为PDF
- Java中WeakReference、WeakHashMap、SoftReference、ReferenceQueue的作用和使用场景 .
- 日志统计归类
- 安卓开发-Activity状态的转换
- POJ 3624 Charm Bracelet