ScreenSaver + 'APPDATA' = AWOL

BlitzMax Forums/BlitzMax Programming/ScreenSaver + 'APPDATA' = AWOL

I've been toying with a screen saver for the last couple of days and I've decided it'd be a good idea to keep the config file in the 'APPDATA' folder by reading the environment variable 'APPDATA' to retrieve the path of this folder.

Everything works well and the config file is read when I double click the saver, when I right click and hit 'Test' and when the saver is run via the 'Preview' button on the screen saver properties window.

However, if the saver is allowed to start normally (ie times out), the config file can't be found because 'APPDATA' is returning null.

I've used both 'getenv_()' and GetEnvironmentVariable() to retrieve the variables value, without much success.


Am I missing something here, or has anyone got any ideas?

Cheers....



[edit]
Sorry about the cryptic thread title...It seemed like a good idea at the time. ;o)

I forgot to mention that other environment variables, such as 'USERPROFILE' and 'ALLUSERSPROFILE', work fine.
[/edit]

If you wanna try this for yourself...
'compile and rename me as *.scr

Strict

Extern "win32"
	Function GetEnvironmentVariable(lpName$z, lpBuffer:Byte Ptr, nSize) = "GetEnvironmentVariableA@12"
End Extern

Local appData1$ = getenv_("APPDATA")
Local appData2$ = GetEnv("APPDATA")

Graphics 800, 600, 32 

ClearEventQueue()

Repeat
	Select PollEvent()
		Case EVENT_KEYDOWN, EVENT_MOUSEDOWN
			End
	End Select
	
	Cls
	DrawText "'APPDATA' = " + appData1$, 12, 12
	DrawText "'APPDATA' = " + appData2$, 12, 24
	
	Flip
Forever

End	

Function GetEnv$(envVar$)
		Local buff@[64]
		
		Local rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		If rtn > buff.length
			buff@ = buff@[..rtn]
			rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		EndIf
		
		Return string.FromBytes(buff@, rtn)
End Function

Function ClearEventQueue()
	Repeat ; Until PollEvent() = 0
End Function


No one got any ideas about this?

I don't want to use the registry, unless I really have to.

Could someone please compile the above and confirm the same thing happens on their system?

Thanks...

I compiled it, installed it, and got the same results you did. I'm not sure why the appdata is null when the screensaver is activated by the OS. I would use the registry. That's what I use for my screensavers.

Thanks very much for trying it, Joe.

It's a bit weird that it seems only to be 'APPDATA' that's affected. :o/


Yeah, I've reluctantly changed over to using the registry. I presume 'HKEY_CURRENT_USER\Software\..' is the correct/best place to put this stuff?

Yup! That's the place :)

[bestest Bruce Campbell Voice]Groovy![/bestest Bruce Campbell Voice]

Cheers again...