日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

Windows API获取系统配置文件的配置参数

發(fā)布時(shí)間:2025/7/14 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows API获取系统配置文件的配置参数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在Windows平臺(tái)下獲取系統(tǒng)配置文件(如:System.ini)的配置參數(shù)。

系統(tǒng)配置文件System.ini的內(nèi)容如下:

[SYSTEM]
ServiceIP = 10.128.11.99:60000
CommuType = ShareMemory


代碼如下:

包含頭文件?Winbase.h (include Windows.h)

?

//GetCurrentPath()函數(shù)獲取可執(zhí)行模塊的全路徑,并將路徑中的"\\"變?yōu)椤甛’,之后去掉了路徑中的可執(zhí)行文件的名字 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對(duì)應(yīng)的值,如果沒有獲取到,則以默認(rèn)值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()獲取系統(tǒng)文件中ServiceIP鍵的值 void GetSystemIPConfig( char *szReciBuff,int nLen ) { string strDefaultV="127.0.0.1:60000"; GetSystemConfig("ServiceIP",strDefaultV,szReciBuff,nLen); } //GetSystemCommTypeConfig()獲取系統(tǒng)文件中ShareMemory鍵的值 void GetSystemCommTypeConfig( char *szReciBuff,int nLen ) {string strDefaultV="ShareMemory";GetSystemConfig("CommuType",strDefaultV,szReciBuff,nLen); } //測(cè)試代碼: int main() {char szCommuType[256]="";GetSystemCommTypeConfig(szCommuType,256);GetSystemIPConfig(szCommuType,256); }


?

?

總結(jié)

以上是生活随笔為你收集整理的Windows API获取系统配置文件的配置参数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。