getprivateprofilestring API Help needed

hemenkap

Active member
Joined
Jan 22, 2003
Messages
29
Location
Mumbai, India.
I wanted to write some form level settings in an ini file.
i was abel to write them using the writeprivateprofilestring API
call but i am unable to use the GetPrivateProfileString to Retrive the written values back.

can you help me how to do that?

Hemen Kapadia
 
sorry about the delay lol.
Code:
Imports System.Text
///at top of code page^^^

    <DllImport("kernel32.dll")> _
        Private Overloads Shared Function WritePrivateProfileString( _
        ByVal lpApplicationName As String, _
        ByVal lpKeyName As String, _
        ByVal lpString As String, _
        ByVal lpFileName As String) As Integer
    End Function
    <DllImport("kernel32.dll")> _
        Private Overloads Shared Function GetPrivateProfileString( _
            ByVal lpApplicationName As String, _
            ByVal lpKeyName As String, _
            ByVal lpDefault As String, _
            ByVal lpReturnedString As StringBuilder, _
            ByVal nSize As Integer, _
            ByVal lpFileName As String) As Integer
    End Function
/// under the designer generated code area^^^

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WritePrivateProfileString("this", "KeyName", "This is the value", "c:\test.ini")
        Dim str As New StringBuilder(256)
        Dim l As Integer
        l = GetPrivateProfileString("this", "KeyName", "Default", str, str.Capacity, "C:\test.ini")
        MsgBox(str.ToString())
    End Sub
took a bit of messing about but i got it to run , the basis of it is from a vb6 code on allapi.net, but i modified it all to work in .net
 
Back
Top