Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

medovid

INI files in VB6

This topic is 5764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to read from/write to INI files from VB6 and I cannot stand the regular method of reading and writing .txt files ( the "as input" stuff) So I was wondering if anyone could help me use the win api function - "getprivateprofilestring".Acc. to MSDN one of the arguments is something that "points to destination buffer" That is apparently from C and I do not know C so I was wondering how I can do this in VB. THANK YOU

Share this post


Link to post
Share on other sites
Advertisement
An alternative would be to use the scripting library (Microsoft Scripting Runtime, it needs to be added via Project | References). The functionality available is clearer and there is plenty of documentation on MSDN.

Share this post


Link to post
Share on other sites
To pass a buffer to a Win32 API function from within VB, you have to create a fixed length string to act as the buffer.

To do that, use Dim str as String * 255 or whatever length you want.

this should give you an idea about using Get/WritePrivateProfileString


  
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Function GetIniString(Section As String, Key As String) As String

Dim val As String * 255
val = ""
Call GetPrivateProfileString(Section, Key, "
", val, 255, App.Path & "\Test.ini")

GetIniString = val

End Function

Sub WriteIniString(Section As String, Key As String, val As String)
If Len(val) > 255 Then
Err.Raise 1
Else
Call WritePrivateProfileString(Section, Key, val, App.Path & "
\Test.ini")
End If
End Sub

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!