Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • 1 month later...
  • Leaders
Posted

sorry about the delay lol.

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...