473,511 Members | 9,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetPrivateProfileString

I am trying to return a string from an .ini file, and keep getting the
following error:
"Arithmetic operation resulted in an overflow".

Has anyone seen this error before? What am I doing wrong?

Thanks!
Jul 21 '05 #1
3 3091
could you post the code you are using to get the ini value?

"kvrdeveloper1" wrote:
I am trying to return a string from an .ini file, and keep getting the
following error:
"Arithmetic operation resulted in an overflow".

Has anyone seen this error before? What am I doing wrong?

Thanks!

Jul 21 '05 #2
> could you post the code you are using to get the ini value?

The code that I am using is below. The values of the variables are as
follows: psSection: "LogOn", psEntry: "DBType", psDefault: "Microsoft SQL
Server", sReturnVal = Nothing, iBUFFER = 255, psFileName:
"C:\path\setting.ini"

Private Function gsGetProfileString(ByVal psSection As String, ByVal psEntry
As String, ByVal psDefault As String, ByVal psFileName As String) As String

Const iBUFFER As Integer = 255
Dim iLength As Integer
Dim sReturnVal As String

iLength = GetPrivateProfileString(psSection, psEntry, psDefault,
sReturnVal, iBUFFER, psFileName)

gsGetProfileString = Left(sReturnVal, iLength)

End Function

Jul 21 '05 #3
in your getprivateprofilestring function try changing the return value from a
sting to a stringbuilder.
when you call the function make sure to initialize the string builder to
your buffer size ie 255.
dim sReturnVal as System.Text.StringBuilder(250);
The string builder should marshel to an LPTSTR that's buffer can be writen to.
Aaron

"kvrdeveloper1" wrote:
could you post the code you are using to get the ini value?


The code that I am using is below. The values of the variables are as
follows: psSection: "LogOn", psEntry: "DBType", psDefault: "Microsoft SQL
Server", sReturnVal = Nothing, iBUFFER = 255, psFileName:
"C:\path\setting.ini"

Private Function gsGetProfileString(ByVal psSection As String, ByVal psEntry
As String, ByVal psDefault As String, ByVal psFileName As String) As String

Const iBUFFER As Integer = 255
Dim iLength As Integer
Dim sReturnVal As String

iLength = GetPrivateProfileString(psSection, psEntry, psDefault,
sReturnVal, iBUFFER, psFileName)

gsGetProfileString = Left(sReturnVal, iLength)

End Function

Jul 21 '05 #4

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

Similar topics

4
19177
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...
1
3914
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
5
19629
by: L | last post by:
static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); Interoping...
1
3630
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...
5
7635
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...
2
3735
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...
1
1659
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...
6
3783
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,...
0
7251
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,...
0
7430
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...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5673
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,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
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...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
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...

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.