Seems to be ok in a virtual machine with one monitor.
I also tried:
CoInitialize(NULL);
HRESULT hr;
IActiveDesktop *pActiveDesktop;
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop);
if (S_OK == hr)
{
#ifdef _UNICODE
WCHAR * wszImageLocation = wallpaper;
#else
WCHAR wszImageLocation[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, wallpaper, -1, wszImageLocation, MAX_PATH);
#endif
HRESULT hr = pActiveDesktop->SetWallpaper(wszImageLocation, 0);
DebugOut(_T("SetWallpaper, hr=0x%08X\r\n"), hr);
hr = pActiveDesktop->ApplyChanges(AD_APPLY_SAVE);
DebugOut(_T("ApplyChanges(AD_APPLY_SAVE), hr=0x%08X\r\n"), hr);
hr = pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
DebugOut(_T("ApplyChanges(AD_APPLY_ALL), hr=0x%08X\r\n"), hr);
hr = pActiveDesktop->Release();
}
IDesktopWallpaper *pDesktopWallpaper = NULL;
hr = CoCreateInstance(CLSID_DesktopWallpaper, NULL, CLSCTX_INPROC_SERVER, IID_IDesktopWallpaper, (void**)&pDesktopWallpaper);
if (FAILED(hr))
{
DebugOut(_T("CoCreateInstance(CLSID_DesktopWallpaper, hr=0x%08X\r\n"), hr);
}
else
{
DebugOut(_T("CoCreateInstance(CLSID_DesktopWallpaper) ok\r\n"));
#ifdef _UNICODE
WCHAR * wszImageLocation = wallpaper;
#else
WCHAR wszImageLocation[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, wallpaper, -1, wszImageLocation, MAX_PATH);
#endif
HRESULT hr = pDesktopWallpaper->SetWallpaper(NULL, wszImageLocation);
DebugOut(_T("SetWallpaper, hr=0x%08X\r\n"), hr);
pDesktopWallpaper->Release();
}
pActiveDesktop->SetWallpaper reports OK but does nothing.
CoCreateInstance(CLSID_DesktopWallpaper,.. ) gives HR=0x80040154 - class not registered.