|
-
Dec 16th, 2003, 04:08 PM
#1
Thread Starter
New Member
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:
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
'.
'.
'.
Dim TheFileName As String
Dim numChars As Integer
Dim objResult As New System.Text.StringBuilder(256)
Dim ReturnString As String
'does not access "C:\WINNT\system.ini"
TheFileName = "C:\WINNT\system.ini"
numChars = GetPrivateProfileString("386enh", "woafont", "<nothing>", objResult, objResult.Capacity, TheFileName)
ReturnString = Left(objResult.ToString, numChars)
'ReturnString is "<nothing>" (should be "dosapp.FON")
'but setting TheFileName to blank (or explicitly to "C:\WINNT\win.ini") will result in success when getting a key value from that file
TheFileName = ""
numChars = GetPrivateProfileString("Mail", "CMCDLLNAME", "<nothing>", objResult, objResult.Capacity, TheFileName)
ReturnString = Left(objResult.ToString, numChars)
'ReturnString is "mapi.dll"
-
Dec 16th, 2003, 04:41 PM
#2
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:
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sBuild As New System.Text.StringBuilder(256)
GetPrivateProfileString("386enh", "woafont", "Default", sBuild, sBuild.Capacity, "C:\WINDOWS\system.ini")
MessageBox.Show(sBuild.ToString)
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]
-
Dec 16th, 2003, 05:00 PM
#3
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|