473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reading INI File

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.
Nov 16 '05 #1
1 10022
The parameter "lpReturnedString" in GetPrivateProfileStringA should be
declared as System.Text.StringBuilder since .net standard strings are
immutable.

"Bronislav" <Br*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:68**********************************@microsof t.com...
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.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
2
by: archana | last post by:
Hi all, I am new to asp.net (learning phase). I have to develop application in asp.net to read file from client pc and display statistics of that file to client. So my question is that to...
12
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
3
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to...
6
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a...
1
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is...
1
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.