Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Retreiving data from .ini file.

Hi Everyone.
I'm new to this aspect of .net so be forgiving.
I want to retrieve a database connection string that is stored in an ini file.

This is what I have so far:

<Runtime.InteropServices.DllImport("kernel32", EntryPoint:="GetPrivateProfileStringA")> _
Private Shared Function GetPrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
End Function

Public Function PGetIniStr(ByVal INIsection As String, ByVal INIKey As String, _
ByVal IniFile As String, Optional ByVal KeyLen As Integer = 128) As String
Dim item As New System.Text.StringBuilder(KeyLen)
Dim ret As Integer
ret = GetPrivateProfileString(INIsection, INIKey, "?", item, KeyLen, IniFile)
PGetIniStr = item.ToString
End Function

sSource = PGetIniStr("Company", "dbPath", strPath & "/ini/default.ini")

:confused:
What exactly am I missing here? Am I missing an argument or is my call wrong? I found this when I started working but I'm still stuck:
http://forums.dev-archive.com/showthread.php?t=153896
[1299 byte] By [dstrange] at [2007-11-11 10:04:06]
# 1 Re: Retreiving data from .ini file.
You might want to check out a Class that has already been written for this purpose:

http://www.mentalis.org/soft/class.qpx?id=6
pclement at 2007-11-11 21:44:57 >