[DllImport("kernel32.dll")]
static extern uint GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
uint nSize,
string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in
certain cases:
StringBuilder buffer has been overflowed by unmanaged code. The
process may become unstable. Insufficient capacity allocated to the
StringBuilder before marshaling it."
public void ReadINIFile()
{
try
{
GetPrivateProfileString("Directories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfileString("Directories" , "Out", "c:\\xmldata" ,
_strOutDir,80, _strINIFile);
GetPrivateProfileString("System" , "IPAddress", "198.190.229.101" ,
_strIP,80, _strINIFile);
GetPrivateProfileString("System" , "UserID", "jw" , _strUser,80,
_strINIFile);
GetPrivateProfileString("System" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfileString("Time" , "BusyTimeStart", "14:30" ,
_strBusyTimeStart,80, _strINIFile);
GetPrivateProfileString("Time" , "BusyTimeEnd", "15:30" ,
_strBusyTimeEnd,80, _strINIFile);
GetPrivateProfileString("Time" , "BusyTimeIntervalInMin", "1" ,
_strBusyTimeIntervalInMin,80, _strINIFile);
GetPrivateProfileString("Time" , "RegTimeIntervalInMin", "5" ,
_strRegTimeIntervalInMin,80, _strINIFile);
GetPrivateProfileString("File" , "MainFrame to PC File extension",
"false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}
Does anybody have a solution to this?
Thanks,
Lalasa. 5 19610
"L" <la********@investors.com> wrote in message [DllImport("kernel32.dll")] static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
You may want to use a more explicit declaration of this function:
[DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileStringA",
CharSet=CharSet.Ansi)]
private static extern int GetPrivateProfileString (string lpApplicationName,
string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int
nSize, string lpFileName);
StringBuilder buffer has been overflowed by unmanaged code. The process may become unstable. Insufficient capacity allocated to the StringBuilder before marshaling it."
How did you initialize the StringBuilder?
Does anybody have a solution to this? http://www.mentalis.org/soft/class.qpx?id=6
Regards,
Pieter Philippaerts
You need to initialize the StringBuilder with the appropriate initial size.
StringBuilder _strInDir = new StringBuilder(80);
David Anton www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
"L" wrote: [DllImport("kernel32.dll")] static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in certain cases:
StringBuilder buffer has been overflowed by unmanaged code. The process may become unstable. Insufficient capacity allocated to the StringBuilder before marshaling it."
public void ReadINIFile() { try { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml", _strInDir,80, _strINIFile); GetPrivateProfileString("Directories" , "Out", "c:\\xmldata" , _strOutDir,80, _strINIFile); GetPrivateProfileString("System" , "IPAddress", "198.190.229.101" , _strIP,80, _strINIFile); GetPrivateProfileString("System" , "UserID", "jw" , _strUser,80, _strINIFile); GetPrivateProfileString("System" , "Password", "jason" , _strPwd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeStart", "14:30" , _strBusyTimeStart,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeEnd", "15:30" , _strBusyTimeEnd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeIntervalInMin", "1" , _strBusyTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("Time" , "RegTimeIntervalInMin", "5" , _strRegTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile); } catch (Exception ex) { throw ex; } }
Does anybody have a solution to this?
Thanks, Lalasa.
Hi,
I figured that out but I have more questions regarding using
StringBuilder. I am also using WritePrivateProfileString and whenever I
want to assign a value to the string builder before I do a
WritePrivateProfileString, have I no choice but to do a new
StringBuilder(value), every time I want to assign a new value to the
StringBuilder type variable. Will that affect the amount of memory
used?
for ex : I have my class
public class INIFileOp
{
/* private members */
private StringBuilder _strInDir = new StringBuilder(80);
...
/* properties */
public string InputDir
{
get { return _strInDir.toString();
set { _strInDir = new StringBuilder(value); } // Do I have to
do the new every time I set the value?
}
...
/* Methods */
public void WriteINIFile()
{
WritePrivateProfileString("Directories", "In", _strInDir,
_strINIFile);
...
...
}
public void ReadINIFile()
{
GetPrivateProfileString("Directories" , "In" ,
"(rg)data/xml",_strInDir,80, _strINIFile);
...
...
}
}
public class Test
{
INIFileOp objINIFileOp = new INIfileOp();
objINIFileOp.ReadINIFile();
objINIFileOp.InputDir = "xyz/xyz"; // Actually in my code values
will be read from the form fields and set to the properties of
INIFileOp class.
objINIFileOp.WriteINIFile();
}
Any comments on using StringBuilders and the way I am doing it?
Thanks,
Lalasa.
David Anton wrote: You need to initialize the StringBuilder with the appropriate initial
size. StringBuilder _strInDir = new StringBuilder(80);
David Anton www.tangiblesoftwaresolutions.com Home of the Instant C# VB.NET to C# converter and the Instant VB C#
to VB.NET converter
"L" wrote:
[DllImport("kernel32.dll")] static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in certain cases:
StringBuilder buffer has been overflowed by unmanaged code. The process may become unstable. Insufficient capacity allocated to
the StringBuilder before marshaling it."
public void ReadINIFile() { try { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml", _strInDir,80, _strINIFile); GetPrivateProfileString("Directories" , "Out", "c:\\xmldata" , _strOutDir,80, _strINIFile); GetPrivateProfileString("System" , "IPAddress",
"198.190.229.101" , _strIP,80, _strINIFile); GetPrivateProfileString("System" , "UserID", "jw" ,
_strUser,80, _strINIFile); GetPrivateProfileString("System" , "Password", "jason" , _strPwd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeStart", "14:30" , _strBusyTimeStart,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeEnd", "15:30" , _strBusyTimeEnd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeIntervalInMin", "1" , _strBusyTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("Time" , "RegTimeIntervalInMin", "5" , _strRegTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("File" , "MainFrame to PC File
extension", "false" , _strFile,80, _strINIFile); } catch (Exception ex) { throw ex; } }
Does anybody have a solution to this?
Thanks, Lalasa.
Note that while the GetPrivateProfileString requires a StringBuilder as a
parameter, WritePrivateProfileString does not. So if you're doing a lot of
string manipulation then you can just use a regular string as a parameter and
argument to WritePrivateProfileString.
David Anton www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
"L" wrote: Hi,
I figured that out but I have more questions regarding using StringBuilder. I am also using WritePrivateProfileString and whenever I want to assign a value to the string builder before I do a WritePrivateProfileString, have I no choice but to do a new StringBuilder(value), every time I want to assign a new value to the StringBuilder type variable. Will that affect the amount of memory used?
for ex : I have my class
public class INIFileOp {
/* private members */ private StringBuilder _strInDir = new StringBuilder(80); ...
/* properties */ public string InputDir { get { return _strInDir.toString(); set { _strInDir = new StringBuilder(value); } // Do I have to do the new every time I set the value? }
...
/* Methods */ public void WriteINIFile() { WritePrivateProfileString("Directories", "In", _strInDir, _strINIFile); ... ... }
public void ReadINIFile() { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml",_strInDir,80, _strINIFile); ... ... }
}
public class Test { INIFileOp objINIFileOp = new INIfileOp(); objINIFileOp.ReadINIFile(); objINIFileOp.InputDir = "xyz/xyz"; // Actually in my code values will be read from the form fields and set to the properties of INIFileOp class. objINIFileOp.WriteINIFile();
}
Any comments on using StringBuilders and the way I am doing it?
Thanks, Lalasa. David Anton wrote: You need to initialize the StringBuilder with the appropriate initial size. StringBuilder _strInDir = new StringBuilder(80);
David Anton www.tangiblesoftwaresolutions.com Home of the Instant C# VB.NET to C# converter and the Instant VB C# to VB.NET converter
"L" wrote:
[DllImport("kernel32.dll")] static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in certain cases:
StringBuilder buffer has been overflowed by unmanaged code. The process may become unstable. Insufficient capacity allocated to the StringBuilder before marshaling it."
public void ReadINIFile() { try { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml", _strInDir,80, _strINIFile); GetPrivateProfileString("Directories" , "Out", "c:\\xmldata" , _strOutDir,80, _strINIFile); GetPrivateProfileString("System" , "IPAddress", "198.190.229.101" , _strIP,80, _strINIFile); GetPrivateProfileString("System" , "UserID", "jw" , _strUser,80, _strINIFile); GetPrivateProfileString("System" , "Password", "jason" , _strPwd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeStart", "14:30" , _strBusyTimeStart,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeEnd", "15:30" , _strBusyTimeEnd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeIntervalInMin", "1" , _strBusyTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("Time" , "RegTimeIntervalInMin", "5" , _strRegTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile); } catch (Exception ex) { throw ex; } }
Does anybody have a solution to this?
Thanks, Lalasa.
I meant "if you're *not* doing a lot of string manipulation..." of course.
"L" wrote: Hi,
I figured that out but I have more questions regarding using StringBuilder. I am also using WritePrivateProfileString and whenever I want to assign a value to the string builder before I do a WritePrivateProfileString, have I no choice but to do a new StringBuilder(value), every time I want to assign a new value to the StringBuilder type variable. Will that affect the amount of memory used?
for ex : I have my class
public class INIFileOp {
/* private members */ private StringBuilder _strInDir = new StringBuilder(80); ...
/* properties */ public string InputDir { get { return _strInDir.toString(); set { _strInDir = new StringBuilder(value); } // Do I have to do the new every time I set the value? }
...
/* Methods */ public void WriteINIFile() { WritePrivateProfileString("Directories", "In", _strInDir, _strINIFile); ... ... }
public void ReadINIFile() { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml",_strInDir,80, _strINIFile); ... ... }
}
public class Test { INIFileOp objINIFileOp = new INIfileOp(); objINIFileOp.ReadINIFile(); objINIFileOp.InputDir = "xyz/xyz"; // Actually in my code values will be read from the form fields and set to the properties of INIFileOp class. objINIFileOp.WriteINIFile();
}
Any comments on using StringBuilders and the way I am doing it?
Thanks, Lalasa. David Anton wrote: You need to initialize the StringBuilder with the appropriate initial size. StringBuilder _strInDir = new StringBuilder(80);
David Anton www.tangiblesoftwaresolutions.com Home of the Instant C# VB.NET to C# converter and the Instant VB C# to VB.NET converter
"L" wrote:
[DllImport("kernel32.dll")] static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in certain cases:
StringBuilder buffer has been overflowed by unmanaged code. The process may become unstable. Insufficient capacity allocated to the StringBuilder before marshaling it."
public void ReadINIFile() { try { GetPrivateProfileString("Directories" , "In" , "(rg)data/xml", _strInDir,80, _strINIFile); GetPrivateProfileString("Directories" , "Out", "c:\\xmldata" , _strOutDir,80, _strINIFile); GetPrivateProfileString("System" , "IPAddress", "198.190.229.101" , _strIP,80, _strINIFile); GetPrivateProfileString("System" , "UserID", "jw" , _strUser,80, _strINIFile); GetPrivateProfileString("System" , "Password", "jason" , _strPwd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeStart", "14:30" , _strBusyTimeStart,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeEnd", "15:30" , _strBusyTimeEnd,80, _strINIFile); GetPrivateProfileString("Time" , "BusyTimeIntervalInMin", "1" , _strBusyTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("Time" , "RegTimeIntervalInMin", "5" , _strRegTimeIntervalInMin,80, _strINIFile); GetPrivateProfileString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile); } catch (Exception ex) { throw ex; } }
Does anybody have a solution to this?
Thanks, Lalasa.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Hayworth |
last post by:
Randy:
I too am having the problem that this other guy/girl had. I put in
the proper API declarations and arguments for GetPrivateProfileString
yet it doesn't return the correct stuff. It always...
|
by: Germic |
last post by:
Does C# has an equivalent of the 'C' GetPrivateProfileString? or is the only
way to get similar features to read from an INI file is to do a DllImport on
Kernel32.dll?
Thanks
|
by: Lalasa |
last post by:
I got GetPrivateProfileString to work using interop, but there is
something that is bugging me.
This is the syntax provided on Pinvoke.net
static extern uint GetPrivateProfileString(
string...
|
by: Domac |
last post by:
I need to read some configuration data from .ini file located at
Application.StartupPath location .
Here is code snippet :
Public Declare Unicode Function GetPrivateProfileString Lib...
|
by: 海风 |
last post by:
A question about GetPrivateProfileString
a section in a .ini file , for example
ip = 192.168.1.112
....
i want to get the ip value by using GetPrivateProfileString() function.
the code...
|
by: Nhan |
last post by:
Hi,
I am trying to use the function GetPrivateProfileString as following:
public static extern Int32 GetPrivateProfileString(string lpAppName, string
lpKeyName, string lpDefault, string...
|
by: thiago777 |
last post by:
Is there a better way of accomplishing this ?: http://msdn2.microsoft.com/en-us/library/ms724353.aspx
I have some program settings which should be easily editable by the user (really like in a...
|
by: alag20 |
last post by:
Hi Guys,
I need some urgent help with this as I am becoming clueless now.
I have 2 DllImport as below from Kernel32
private static extern int GetPrivateProfileString(string section, int key,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |