|
-
July 26th, 2002, 08:52 AM
#1
Read INI file with GetPrivateProfileString
Hello,
I'm trying to read an ini file with the API Call GetPrivateProfileString. The code below works in VB6, but not in VB.NET. Does anybody know why. Please let me know if u do!
Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal _
lpReturnedString As String, ByVal nSize As Long, ByVal _
lpFileName As String) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strRetString As String
strRetString = " "
Dim lngRetval As Long
lngRetval = GetPrivateProfileString("SECTIONNAME", "KEYNAME", "Default Value", strRetString, Len(strRetString), "C:\AnIniFile.ini")
End Sub
Last edited by JohnDigweed; July 26th, 2002 at 09:11 AM.
Regards,
John Digweed
-
July 26th, 2002, 09:28 AM
#2
I haven't tested, but try changing you DIM of strRetString to:
Dim strRetString As New String(Space(100))
or
Dim strRetString as New String(" ")
-
July 26th, 2002, 11:25 AM
#3
Thanx for your response but this also does not work. If you have any other ideas please let met know.
John
Regards,
John Digweed
-
July 26th, 2002, 02:35 PM
#4
Classic beginner mistake for both of us... VB 6's LONG should now be INTEGER, try this:
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal _
lpReturnedString As String, ByVal nSize As Integer, ByVal _
lpFileName As String) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strRetString As New String(Space(50))
Dim lngRetval As Long
lngRetval = GetPrivateProfileString("SECTIONNAME", "KEYNAME", "Default Value", strRetString, strRetString.Length, "C:\AnIniFile.ini")
If lngRetval <> 0 Then
MsgBox(strRetString.Trim)
End If
End Sub
-
July 29th, 2002, 03:21 AM
#5
GetPrivateProfileString
Regards,
John Digweed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|