Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: IActiveDesktop::SetWallpaper from Perl?

by blm (Hermit)
on Oct 19, 2002 at 14:16 UTC ( [id://206513]=note: print w/replies, xml ) Need Help??


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:

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

Replies are listed 'Best First'.
(bbfu) Re (ATL COM): IActiveDesktop::SetWallpaper from Perl?
by bbfu (Curate) on Oct 19, 2002 at 18:41 UTC

    Thanks, blm. This seems like the best solution so far to me. Unfortunately, I don't have Visual Studio. :( Do you know if it's possible to create a COM object, or even just create an IActiveDesktop instance, with a normal C++ compiler? I have Bloodshed Dev C++ (basically an IDE for the mingw compiler). Would it be impractical to create a COM object with that? Any pointers on how to go about it if it's feasable?

    Anyway, thanks again! :)

    bbfu
    Black flowers blossum
    Fearless on my breath

      From the FAQ

      Is support provided for COM? MinGW has some support for COM programs. Programmers have had much better luck writing COM applications in C than C++. Work is in progress to improve support. Check the MinGW mailing list archives for more details on COM and more links to example files.

      I am sorry I can't offer more then that. All I can say is good luck if you go this way

      --blm--

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://206513]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found