Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SystemParametersInfo sets wallpaper completly black (using SPI_SETDESKWALLPAPER)

I try to change my desktop wallpaper. It works just fine when I use it like this:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\1.jpg", SPIF_SENDCHANGE);

But when I use it like this, the desktop wallpaper is set completly black:

std::string s = "C:\\1.jpg";
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, &s, SPIF_SENDCHANGE);

I tried to get some more info via using GetLastError(), but the return value is just 0. I also tried to use .png-files, but this doesn't change anything.

Any ideas what I am doing wrong?

like image 890
aasoo Avatar asked Dec 14 '25 06:12

aasoo


1 Answers

Try this:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)s.c_str(), SPIF_SENDCHANGE);

The SystemParametersInfo function doesn't accept std::string pointer as path, it accepts a null-terminated char array. Which is what the c_str() method of std::string provides.

like image 107
Violet Giraffe Avatar answered Dec 15 '25 18:12

Violet Giraffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!