473,386 Members | 2,129 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,386 software developers and data experts.

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 3084
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
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
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
by: L | last post by:
static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); Interoping...
1
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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$) { } ...
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: 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...
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
Oralloy
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,...
0
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...

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.