Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using GetPrivateProfileString API

Status
Not open for further replies.

khnp

Programmer
Oct 15, 2003
5
US
I am trying to read an ini file. This is the way is setup. The comments refer to the value obtained for the variable in question.

Private Declare Function GetPrivateProfileStringKey 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

Public Sub Main()
Dim r as Long
r = GetWindowsDirectory(Buffer, Len(Buffer))
WinPath = Left(Trim(Buffer), r)
WinPath = WinPath & "\" & "epay.ini"
'WinPath = "c:\winnt\epay.ini" which is correct
Buffer = ""
Dim TempStr As String
TempStr = New String(CChar(" "), 255)
r = GetPrivateProfileStringKey("SchCrystal", "bPrinter", "", TempStr, Len(TempStr), WinPath)

'the value of TempStr should be "1" yet the value on debugging is "". I have read ini in VB before using similar code but do not seem to be able to do it for first time in VB Net. Can anybody help? Thanks in advance.

By the way I would like to dispense with reading ini if possible. I just need to pass six parameters to the app but I am not an expert in VB and have never declared incoming parameters into a VB App. If anybody can help me by looking at the code to read the ini and giving me some advice on how to fix it or telling me how to declare the incoming parameters I will be grateful. My starting and only sub is Main(). Should it be Public Sub Main(Param1 as string, Param2 as string.....)

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top