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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CallFn("GetPrivateProfileString" ... ) not working 1

Status
Not open for further replies.

ChrisCarroll

Programmer
Oct 10, 2000
177
Can anyone help ...

WritePrivateProfileString works fine- the file C:\(windir)\test.ini is correctly updated each time.

But cResult always comes back unchanged. How do I Get the setting?

I got the WinAPI signatures from VB4 help files - they both register as given, so I assume they're correct. I'm running on NT4

Code:
Public iWritePPString, iGetPPString, cReturn, cDefault
Set library to FoxTools

iWritePPString= RegFn("WritePrivateProfileString", "CCCC", "L") 

	*(ByVal lpApplicationName As String,
	* ByVal lpKeyName As Any,
	* ByVal lpString As Any,
	* ByVal lpFileName As String)


iGetPPString= RegFn("GetPrivateProfileString", "CCC@CLC", "L" , "krnl386.exe")
              * That's hopefully an ampersand you see in the signature

	* (ByVal lpApplicationName As String, 
	*  ByVal lpKeyName As Any, 
	*  ByVal lpDefault As String, 
	*  ByVal lpReturnedString As String, 
	*  ByVal nSize As Long, 
	*  ByVal lpFileName As String) As Long

* Get ready ...
	Clear
	cReturn= Repl("_", 15)
	cDefault=Repl("*",15)
	i=0
	? cReturn, cDefault, i

* Write & Read to ini file
	i= CallFn(iWritePPString, "FoxPro", "Setting3", TRIM(str(Rand()*1000, 3,0)) , "Test.ini")
	i= CallFn(iGetPPString, "FoxPro",   "Setting3", cDefault, @cReturn, 15, "Test.ini")

* Show results

	? cReturn, cDefault, i
	modi file c:\winnt\test.ini nowait
 
Oops, sorry misprint there:

iGetPPString= RegFn("GetPrivateProfileString", "CCC@CLC", "L")
* And the "ampersand hash 64 semicolon" in the first post is actually Chr(64) , as in pass by reference

 
Chris,
Change your declarations to:
iWritePPString= RegFn("WritePrivateProfileString", "CCCC", "I")

and

iGetPPString= RegFn("GetPrivateProfileString", "CCC@CIC", "I" , "krnl386.exe")

i.e. Change the "L"s to "I"s, and it seems to work correctly.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top