void ReadwriteINI()
{
CString csIniPath,csKey;
int nPos;
char lpszKeyNames[4096];
DWORD dSize;
dSize = sizeof(lpszKeyNames);
csIniPath="settings.ini";
GetPrivateProfileSection( "IPADDRESS" , lpszKeyNames , dSize , csIniPath );
char *pKeyName = lpszKeyNames;
CString csIP(""), csMyKey(""),csSubnet,csProxyIP,csGateway ,csPort;
while (*pKeyName != 0x00)
{
nPos = -1;
if(*pKeyName != 0x00)
{
csKey = pKeyName;
if((nPos = csKey.Find("=")) > -1)
{
csMyKey = csKey.Left(nPos);
if( csMyKey.Find("IPADDR") > - 1 )
{
csIP= csKey.Mid(nPos+1);
}
if( csMyKey.Find("SUBNET") > - 1 )
{
csSubnet= csKey.Mid(nPos+1);
}
if( csMyKey.Find("GATEWAY") > - 1 )
{
csGateway= csKey.Mid(nPos+1);
}
if( csMyKey.Find("PROXYIP") > - 1 )
{
csProxyIP= csKey.Mid(nPos+1);
}
if( csMyKey.Find("PORT") > - 1 )
{
csPort= csKey.Mid(nPos+1);
}
}
}
pKeyName = pKeyName + strlen(pKeyName) + 1;
}
if(csIP.IsEmpty())
{
csIP="192.168.0.2;
WritePrivateProfileString("IPADDRESS","IPADDR",csIP,csIniPath);
}
if(csSubnet.IsEmpty())
{
csSubnet="255.255.255.0";
WritePrivateProfileString("IPADDRESS","SUBNET ",csSubnet,csIniPath);
}
if(csGateway.IsEmpty())
{
csGateway="192.168.0.3";
WritePrivateProfileString("IPADDRESS","GATEWAY",csGateway,csIniPath);
}
if(csProxyIP.IsEmpty())
{
csProxyIP="198.168.0.1";
WritePrivateProfileString("IPADDRESS","PROXYIP",csProxyIP,csIniPath);
}
if(csPort.IsEmpty())
{
csPort="3128";
WritePrivateProfileString("IPADDRESS","PORT",csPort,csIniPath);
}
}
INI file content:
[IPADDRESS] IPADDR= SUBNET= GATEWAY= PROXYIP= PORT=
Search This Blog
Thursday, April 16, 2009
Read and write .ini files
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment