Okay, for starters, before we get going into my problem, here's something: in the MSDN 6 library, from cd, it says that if your call to SystemParametersInfo fails, to use GetLastError. Fine, no problem here. Then, for GetLastError, it directs you to FormatMessage to get a string describing the problem. And, in the FormatMessage info, it tell you to go back to GetLastError if it fails.
Here's a question: what if you have problems making the FormatMessage function work? Can you really go back to GetLastError? I mean, you can call it, but how do you get useful information about the error without FormatMessage?
</rant>
Okay, now, onto my real problem.
I'm attempting to use the SystemParametersInfo function to change the background. It's not going well.
if( !SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,
"C:\\Documents and Settings\\Naim\\My Documents\\My Pictures\\naruto wallpapers\\Naruto022.jpg",
SPIF_UPDATEINIFILE) ){
char* str = NULL; // function allocates the mem with LocalAlloc(), used with LocalFree()
int msg_ret = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | // let the function alloc string mem
FORMAT_MESSAGE_FROM_SYSTEM | // use system message and not a passed one
FORMAT_MESSAGE_IGNORE_INSERTS, // ignore and "inserts"
NULL,
GetLastError(), // get the error
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
(char*)&str,
0,
NULL);
printf( "\n Error: Desktop wallpaper change failed."
"\n Error message: %s"
"\n", str);
LocalFree(str); // free the local mem allocated
exit(1);
}
I got the SystemParametersInfo function from the other topic that was recently in the beginners forum, something about the program taking all the CPU time because he wasn't Sleep'ing it.
Anyway, there's a random thing going on before the System.... call, but I've hardcoded everything until I get it going. For starters: yes, the file does exist in that directory, and it is a valid jpg file.
Second, I get a strange string back from the FormatMessage function. Here's the total output:
Error: Desktop wallpaper change failed.
Error message: The operation completed successfully.
For an error message, that is honestly one of the least helpful I've seen.
And, MSDN actually says:
Quote:
If the function fails, the return value is zero. To get extended error information, callGetLastError.
So, does anyone know how to use this function properly?
Edit:: Also, I saved the file to a bmp and tried to use that as the filename, and, well it didn't work, the background stayed the same, but, the function was successful, it didn't enter the if.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper