Results 1 to 3 of 3

Thread: Help with GetPrivateProfileString

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    2

    Help with GetPrivateProfileString

    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"

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    i tried it on C:\Windows\System.ini and it worked fine , but you must replace your " Longs " with " Integers " , as vb.net doesnt like longs much in Api's , here's a quick example ....
    VB Code:
    1. Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim sBuild As New System.Text.StringBuilder(256)
    5.         GetPrivateProfileString("386enh", "woafont", "Default", sBuild, sBuild.Capacity, "C:\WINDOWS\system.ini")
    6.         MessageBox.Show(sBuild.ToString)
    7.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    2
    Holy Moley that was it! Thanks much! So simple, yet so elusive....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width