Reputation: 3077
The following code works on Windows 8.1 (tested) but not on Windows 7.
std::wstring loc = L"C:\\Users\User\\Desktop\\wallpaper.jpg";
BOOL ret = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID)loc.c_str(), SPIF_UPDATEINIFILE);
When I run the program on Windows 7 I get the following exception:
First-chance exception at 0x76E3C41F (KernelBase.dll) in MyApp.exe: 0xC0000002: The requested operation is not implemented.
Has anyone came across this before? I've had a look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx and searched Google to no luck.
Upvotes: 1
Views: 729
Reputation: 612794
The only thing that could be wrong with your code is that you are not compiling for Unicode. And so SystemParametersInfo
expands to SystemParametersInfoA
but you pass a wide string. Otherwise your code is correct and does work.
Debugging problems with this particular API call are quite tricky. It doesn't give you much useful feedback. The obvious failure mode is that there is a problem with that specific JPEG file. Perhaps it is not actually a JPEG file in spite of the extension. Or perhaps it uses JPEG features that are not supported by the shell. Or perhaps you got the file name wrong. Those are the sort of things that explain a failure.
I would start debugging this by creating a different JPEG file for test purposes. If that results in success then you know that the issue is the JPEG file that you are using.
Upvotes: 3