in reply to IActiveDesktop::SetWallpaper from Perl?
I can't find the ProgID that matches that CLSID but according to a post by Jan Dubois it is alright to specify a CLSID instead. Win32::OLE determines which it has been passed by the presence of digits. However to my disappointment I found that this does not work:
It gives an erroruse strict; use warnings; use Win32::OLE; use Win32::OLE::Variant; use constant CLSID_ACTIVEDESKTOP => '{75048700-EF1F-11D0-9888-006097 +DEACF9}'; my $actdesktop = Win32::OLE->new(CLSID_ACTIVEDESKTOP) or die(); $actdesktop->SetWallpaper('C:\WINNT\winnt256.bmp');
C:\>"C:\Documents and Settings\blm\Desktop\test1212.pl" Win32::OLE(0.1501) error 0x80004002: "No such interface supported" at +C:\Documen ts and Settings\blm\Desktop\test1212.pl line 8 eval {...} called at C:\Documents and Settings\blm\Desktop\tes +t1212.pl l ine 8 Died at C:\Documents and Settings\blm\Desktop\test1212.pl line 8. C:\>
Nothing I tried could make it work. However I may be missing something simple
Anyway, I ended up writing a COM object that I knew would be scriptable using perl that just proxy's between perl and the actual IActiveDesktop. If you have Visual Studio it is relatively easy to create. Create an ATL COM project remembering the name (eg damnit). Select Insert ... ATL Object and give it a name MyDesktop(eg MyDesktop). Then add methods to the interface by right clicking on the Interface in Class view and selecting add method. Here is the code for my SetWallpaper method:
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_SER +VER, 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; }
I could call this code with the following perl code:
use strict; use warnings; use Win32::OLE; use Win32::OLE::Variant; my $adtest = Win32::OLE->new('damnit.MyDesktop') or die(); $adtest->SetWallpaper('C:\WINNT\winnt256.bmp');
Upon running this perl script my desktop wallpaper changed as expected.
Readers please note: I am not a ATL COM guru so use this code at your risk. Thanks
Oh Larry please forgive me for posting C++
--blm--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(bbfu) Re (ATL COM): IActiveDesktop::SetWallpaper from Perl?
by bbfu (Curate) on Oct 19, 2002 at 18:41 UTC | |
by blm (Hermit) on Oct 20, 2002 at 12:25 UTC |