473,804 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetPrivateProfi leString

L
[DllImport("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
Interoping GetPrivateProfi leString 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
{
GetPrivateProfi leString("Direc tories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfi leString("Direc tories" , "Out", "c:\\xmldat a" ,
_strOutDir,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "IPAddress" , "198.190.229.10 1" ,
_strIP,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "UserID", "jw" , _strUser,80,
_strINIFile);
GetPrivateProfi leString("Syste m" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeStart" , "14:30" ,
_strBusyTimeSta rt,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeEn d", "15:30" ,
_strBusyTimeEnd ,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeInterv alInMin", "1" ,
_strBusyTimeInt ervalInMin,80, _strINIFile);
GetPrivateProfi leString("Time" , "RegTimeInterva lInMin", "5" ,
_strRegTimeInte rvalInMin,80, _strINIFile);
GetPrivateProfi leString("File" , "MainFrame to PC File extension",
"false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}

Does anybody have a solution to this?

Thanks,
Lalasa.

Nov 17 '05 #1
5 19692
"L" <la********@inv estors.com> wrote in message
[DllImport("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
You may want to use a more explicit declaration of this function:

[DllImport("KERN EL32.DLL", EntryPoint="Get PrivateProfileS tringA",
CharSet=CharSet .Ansi)]
private static extern int GetPrivateProfi leString (string lpApplicationNa me,
string lpKeyName, string lpDefault, StringBuilder lpReturnedStrin g, 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
Nov 17 '05 #2
You need to initialize the StringBuilder with the appropriate initial size.
StringBuilder _strInDir = new StringBuilder(8 0);

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("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
Interoping GetPrivateProfi leString 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
{
GetPrivateProfi leString("Direc tories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfi leString("Direc tories" , "Out", "c:\\xmldat a" ,
_strOutDir,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "IPAddress" , "198.190.229.10 1" ,
_strIP,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "UserID", "jw" , _strUser,80,
_strINIFile);
GetPrivateProfi leString("Syste m" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeStart" , "14:30" ,
_strBusyTimeSta rt,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeEn d", "15:30" ,
_strBusyTimeEnd ,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeInterv alInMin", "1" ,
_strBusyTimeInt ervalInMin,80, _strINIFile);
GetPrivateProfi leString("Time" , "RegTimeInterva lInMin", "5" ,
_strRegTimeInte rvalInMin,80, _strINIFile);
GetPrivateProfi leString("File" , "MainFrame to PC File extension",
"false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}

Does anybody have a solution to this?

Thanks,
Lalasa.

Nov 17 '05 #3
L
Hi,

I figured that out but I have more questions regarding using
StringBuilder. I am also using WritePrivatePro fileString and whenever I
want to assign a value to the string builder before I do a
WritePrivatePro fileString, have I no choice but to do a new
StringBuilder(v alue), 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(8 0);
...

/* properties */
public string InputDir
{
get { return _strInDir.toStr ing();
set { _strInDir = new StringBuilder(v alue); } // Do I have to
do the new every time I set the value?
}

...

/* Methods */
public void WriteINIFile()
{
WritePrivatePro fileString("Dir ectories", "In", _strInDir,
_strINIFile);
...
...
}

public void ReadINIFile()
{
GetPrivateProfi leString("Direc tories" , "In" ,
"(rg)data/xml",_strInDir, 80, _strINIFile);
...
...
}

}
public class Test
{
INIFileOp objINIFileOp = new INIfileOp();
objINIFileOp.Re adINIFile();
objINIFileOp.In putDir = "xyz/xyz"; // Actually in my code values
will be read from the form fields and set to the properties of
INIFileOp class.
objINIFileOp.Wr iteINIFile();

}

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(8 0);

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("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
Interoping GetPrivateProfi leString 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
{
GetPrivateProfi leString("Direc tories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfi leString("Direc tories" , "Out", "c:\\xmldat a" ,
_strOutDir,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "IPAddress" , "198.190.229.10 1" , _strIP,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "UserID", "jw" , _strUser,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeStart" , "14:30" ,
_strBusyTimeSta rt,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeEn d", "15:30" ,
_strBusyTimeEnd ,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeInterv alInMin", "1" ,
_strBusyTimeInt ervalInMin,80, _strINIFile);
GetPrivateProfi leString("Time" , "RegTimeInterva lInMin", "5" ,
_strRegTimeInte rvalInMin,80, _strINIFile);
GetPrivateProfi leString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}

Does anybody have a solution to this?

Thanks,
Lalasa.


Nov 17 '05 #4
Note that while the GetPrivateProfi leString requires a StringBuilder as a
parameter, WritePrivatePro fileString 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 WritePrivatePro fileString.

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 WritePrivatePro fileString and whenever I
want to assign a value to the string builder before I do a
WritePrivatePro fileString, have I no choice but to do a new
StringBuilder(v alue), 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(8 0);
...

/* properties */
public string InputDir
{
get { return _strInDir.toStr ing();
set { _strInDir = new StringBuilder(v alue); } // Do I have to
do the new every time I set the value?
}

...

/* Methods */
public void WriteINIFile()
{
WritePrivatePro fileString("Dir ectories", "In", _strInDir,
_strINIFile);
...
...
}

public void ReadINIFile()
{
GetPrivateProfi leString("Direc tories" , "In" ,
"(rg)data/xml",_strInDir, 80, _strINIFile);
...
...
}

}
public class Test
{
INIFileOp objINIFileOp = new INIfileOp();
objINIFileOp.Re adINIFile();
objINIFileOp.In putDir = "xyz/xyz"; // Actually in my code values
will be read from the form fields and set to the properties of
INIFileOp class.
objINIFileOp.Wr iteINIFile();

}

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(8 0);

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("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
Interoping GetPrivateProfi leString 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
{
GetPrivateProfi leString("Direc tories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfi leString("Direc tories" , "Out", "c:\\xmldat a" ,
_strOutDir,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "IPAddress" , "198.190.229.10 1" , _strIP,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "UserID", "jw" , _strUser,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeStart" , "14:30" ,
_strBusyTimeSta rt,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeEn d", "15:30" ,
_strBusyTimeEnd ,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeInterv alInMin", "1" ,
_strBusyTimeInt ervalInMin,80, _strINIFile);
GetPrivateProfi leString("Time" , "RegTimeInterva lInMin", "5" ,
_strRegTimeInte rvalInMin,80, _strINIFile);
GetPrivateProfi leString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}

Does anybody have a solution to this?

Thanks,
Lalasa.


Nov 17 '05 #5
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 WritePrivatePro fileString and whenever I
want to assign a value to the string builder before I do a
WritePrivatePro fileString, have I no choice but to do a new
StringBuilder(v alue), 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(8 0);
...

/* properties */
public string InputDir
{
get { return _strInDir.toStr ing();
set { _strInDir = new StringBuilder(v alue); } // Do I have to
do the new every time I set the value?
}

...

/* Methods */
public void WriteINIFile()
{
WritePrivatePro fileString("Dir ectories", "In", _strInDir,
_strINIFile);
...
...
}

public void ReadINIFile()
{
GetPrivateProfi leString("Direc tories" , "In" ,
"(rg)data/xml",_strInDir, 80, _strINIFile);
...
...
}

}
public class Test
{
INIFileOp objINIFileOp = new INIfileOp();
objINIFileOp.Re adINIFile();
objINIFileOp.In putDir = "xyz/xyz"; // Actually in my code values
will be read from the form fields and set to the properties of
INIFileOp class.
objINIFileOp.Wr iteINIFile();

}

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(8 0);

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("kern el32.dll")]
static extern uint GetPrivateProfi leString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedStrin g,
uint nSize,
string lpFileName);
Interoping GetPrivateProfi leString 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
{
GetPrivateProfi leString("Direc tories" , "In" , "(rg)data/xml",
_strInDir,80, _strINIFile);
GetPrivateProfi leString("Direc tories" , "Out", "c:\\xmldat a" ,
_strOutDir,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "IPAddress" , "198.190.229.10 1" , _strIP,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "UserID", "jw" , _strUser,80, _strINIFile);
GetPrivateProfi leString("Syste m" , "Password", "jason" ,
_strPwd,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeStart" , "14:30" ,
_strBusyTimeSta rt,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeEn d", "15:30" ,
_strBusyTimeEnd ,80, _strINIFile);
GetPrivateProfi leString("Time" , "BusyTimeInterv alInMin", "1" ,
_strBusyTimeInt ervalInMin,80, _strINIFile);
GetPrivateProfi leString("Time" , "RegTimeInterva lInMin", "5" ,
_strRegTimeInte rvalInMin,80, _strINIFile);
GetPrivateProfi leString("File" , "MainFrame to PC File extension", "false" , _strFile,80, _strINIFile);
}
catch (Exception ex)
{
throw ex;
}
}

Does anybody have a solution to this?

Thanks,
Lalasa.


Nov 17 '05 #6

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

Similar topics

4
19246
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 returns the default value (padded with huge amount of spaces on the right) and the return value (number of characters read) is some crazy huge number like 51298398749084 Your demo doesn't work in .Net - it's for prior versions of VB, and so the...
1
3962
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
1
447
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 lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString,
1
3660
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 "kernel32" Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
5
7665
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 is :
2
3755
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 lpReturnedString, short nSize, string lpFileName); ....... String sDatabase = "";
1
1683
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 text file), but dont want to use such an old function like GetPrivateProfileString.. maybe an XML file would be the best solution ? thanks
6
3814
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, string defaultValue, byte result, int size, string fileName); private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder result, int size, string fileName);
0
9715
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10353
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.