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:

use 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');
It gives an error

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--

In reply to Re: IActiveDesktop::SetWallpaper from Perl? by blm
in thread IActiveDesktop::SetWallpaper from Perl? by bbfu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.