Hello all,

I've researched numerous posts at this site and others but haven't seen this problem yet. I'm trying to read from an ini file using VB .NET but my call to GetPrivateProfileString ignores the ini filename I pass in and instead defaults to accessing "C:\WINNT\win.ini" I have performed a similar test using VB6 and it works fine. Can someone please help?

VB Code:
  1. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnString As System.Text.StringBuilder, ByVal nSize As Long, ByVal lpFileName As String) As Integer
  2. '.
  3. '.
  4. '.
  5. Dim TheFileName As String
  6. Dim numChars As Integer
  7. Dim objResult As New System.Text.StringBuilder(256)
  8. Dim ReturnString As String
  9.  
  10. 'does not access "C:\WINNT\system.ini"
  11. TheFileName = "C:\WINNT\system.ini"
  12. numChars = GetPrivateProfileString("386enh", "woafont", "<nothing>", objResult, objResult.Capacity, TheFileName)
  13. ReturnString = Left(objResult.ToString, numChars)
  14. 'ReturnString is "<nothing>" (should be "dosapp.FON")
  15.  
  16. 'but setting TheFileName to blank (or explicitly to "C:\WINNT\win.ini") will result in success when getting a key value from that file
  17. TheFileName = ""
  18. numChars = GetPrivateProfileString("Mail", "CMCDLLNAME", "<nothing>", objResult, objResult.Capacity, TheFileName)
  19. ReturnString = Left(objResult.ToString, numChars)
  20. 'ReturnString is "mapi.dll"