G
Guest
I'm trying to read INI File from inside the C#
I Created Class:
public class clsIniFile
{
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int WritePrivateProfileStringA(
string lpApplicationName,
string lpKeyName,
string lpString,
string lpFileName);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int GetPrivateProfileStringA(
string lpApplicationName,
string lpKeyName,
string lpDefault,
string lpReturnedString,
int nSize,
string lpFileName);
public string filename
{
get
{
return filename;
}
set
{
filename = value;
}
}
private const int Max_SectionBuffer = 4096;
private const int Max_EntryBuffer = 255;
public clsIniFile()
{
}
public bool FileExist(string filename)
{
return File.Exists(filename);
}
public void writeEntry(string Section, string EntryName, string Value,
string filename)
{
WritePrivateProfileStringA(Section, EntryName, Value, filename);
}
public string PrivGetString(string Section, string EntryName, string
filename)
{
int nRetVal, nBuffersize;
string sTemp = "";
sTemp = sTemp.PadLeft(255, ' ');
nBuffersize = sTemp.Length;
nRetVal = GetPrivateProfileStringA(Section, EntryName, "", sTemp,
nBuffersize, filename);
if (nRetVal != 0)
return sTemp.Substring(1 , nRetVal);
else
return "";
}
}
End this class works fine when I'm writing to INI File but when I'm trying
to read it always return empty string in the sTemp. What's wrong. Thanks.
I Created Class:
public class clsIniFile
{
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int WritePrivateProfileStringA(
string lpApplicationName,
string lpKeyName,
string lpString,
string lpFileName);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern int GetPrivateProfileStringA(
string lpApplicationName,
string lpKeyName,
string lpDefault,
string lpReturnedString,
int nSize,
string lpFileName);
public string filename
{
get
{
return filename;
}
set
{
filename = value;
}
}
private const int Max_SectionBuffer = 4096;
private const int Max_EntryBuffer = 255;
public clsIniFile()
{
}
public bool FileExist(string filename)
{
return File.Exists(filename);
}
public void writeEntry(string Section, string EntryName, string Value,
string filename)
{
WritePrivateProfileStringA(Section, EntryName, Value, filename);
}
public string PrivGetString(string Section, string EntryName, string
filename)
{
int nRetVal, nBuffersize;
string sTemp = "";
sTemp = sTemp.PadLeft(255, ' ');
nBuffersize = sTemp.Length;
nRetVal = GetPrivateProfileStringA(Section, EntryName, "", sTemp,
nBuffersize, filename);
if (nRetVal != 0)
return sTemp.Substring(1 , nRetVal);
else
return "";
}
}
End this class works fine when I'm writing to INI File but when I'm trying
to read it always return empty string in the sTemp. What's wrong. Thanks.