C2440: Unable to convert const char* to PVOID

I am writing a joke program that will change the image of the desktop: An error occurred in one of the lines of code:

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "sr2.jpg", SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

In the third argument, the compiler swears that it is impossible to convert const char* to PVOID. I think I missed something somewhere. What could be the problem?

Author: Harry, 2019-12-23

1 answers

Formally, the function SystemParametersInfo can change the data pointed to by the third parameter, since it is not a pointer to const.

So formally, you should do this:

char fn[] = "sr2.jpg";
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, fn, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

But, frankly, I doubt that he will be such a freak, so I think in practice you can do with a cast of the type

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PVOID("sr2.jpg"), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

But I didn't tell you that! :)

 5
Author: Harry, 2019-12-23 15:54:06