I am new to VB and is working on VB6 to VB.net migration. One of the solution is migrated successfully and am working on the second one.
Dim temp As New System.Text.StringBuilder(1024)
Public Sub Main()
Dim i As Integer = GetPrivateProfileString("WinFlex", "UserPath", "", temp, 1024, "C:\WINDOWS\Win.Ini")
End Sub
<DllImport("kernel32")> _
Private Function GetPrivateProfileString(ByVal section As String, ByVal key As String, ByVal def As String, ByVal retVal As System.Text.StringBuilder, ByVal size As Integer, ByVal filePath As String) As Integer
End Function
This particular code needs (temp) to return a working directory for my Ini file (something like "C:\WinFlex6\1"), but instead it is returning me a blank value. The same code works on a different solution (someone else migrated it). I am not sure what the issue is, I tried several fixes present on the web but none worked.
Can anyone help me out on this one?
Earlier it was working fine, but after some debugging it stopped working.
Sorry guys, I am naïve in vb therefore was doing this silly mistake. Thanks Steve for bringing this up.
The issue was, I was/am declaring the function in a module.
<DllImport("kernel32")> _
Private Function GetPrivateProfileString(ByVal section As String, ByVal key As String, ByVal def As String, ByVal retVal As System.Text.StringBuilder, ByVal size As Integer, ByVal filePath As String) As Integer
End Function
This function can be "Shared Function" which can be added in a class.
Public Shared Function
Once I declared it as inside a vb class
<DllImport("kernel32")> _
Public Shared Function GetPrivateProfileString(ByVal section As String, ByVal key As String, ByVal def As String, ByVal retVal As System.Text.StringBuilder, ByVal size As Integer, ByVal filePath As String) As Integer
End Function
Bingo! It worked! Thanks to Steve again!!