STDMETHODIMP CMyDesktop::SetWallpaper(BSTR bstrPath) { HRESULT hr; IActiveDesktop *pActiveDesktop; CoInitialize(NULL); //Create an instance of the Active Desktop hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop); hr = pActiveDesktop->SetWallpaper(bstrPath, 0); if (hr != S_OK) { goto error; } hr = pActiveDesktop->ApplyChanges(AD_APPLY_ALL); pActiveDesktop->Release(); return S_OK; error: return hr; }