Home c++ C2440: Unable to convert Const Char * in Pvoid ​​

C2440: Unable to convert Const Char * in Pvoid ​​




I write a joker program that will change desktop image:
In one of the lines of the code an error occurred:

SystemParametersInfo (SPI_SetDeskwallpaper, 0, "sr2.jpg", spif_updateinifile | spif_sendchange);

In the third argument, the compiler swears to the fact that it is impossible to convert Const Char * to Pvoid. It seems I missed something somewhere. What can the problem be?

Answer 1, Authority 100%

Formally SystemparametersInfo function can change the data to which the third parameter indicates, once this 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 might, so I think in practice you can do with the type of

SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, PVOID ("SR2.JPG"), spif_updateinifile | spif_sendchange);

But I did not say that! 🙂

Previous articleBuild a circle from points
Next articleHTML + CSS

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions