检查一下CoCreateInstance的返回结果,看CoCreateInstance是否成功:        IActiveDesktop* pIADesk = NULL;
        HRESULT hr = ::CoCreateInstance(Shlobj::CLSID_ActiveDesktop,
                                        NULL,
                                        CLSCTX_INPROC_SERVER,
                                        IID_IActiveDesktop,
                                        (void**)&pIADesk);
        if(SUCCEEDED(hr)) {
                pIADesk->SetWallpaper(FileName, 0);
                pIADesk->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
                pIADesk->Release();
        }

解决方案 »

  1.   

    检查一下CoCreateInstance的返回结果,看CoCreateInstance是否成功:        IActiveDesktop* pIADesk = NULL;
            HRESULT hr = ::CoCreateInstance(Shlobj::CLSID_ActiveDesktop,
                                            NULL,
                                            CLSCTX_INPROC_SERVER,
                                            IID_IActiveDesktop,
                                            (void**)&pIADesk);
            if(SUCCEEDED(hr)) {
                    pIADesk->SetWallpaper(FileName, 0);
                    pIADesk->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
                    pIADesk->Release();
            }
      

  2.   

    ddeng, 不是的, 我根本连编译都通不过。提示说未知类型'IActiveDesktop', 可是奇怪的是为什么定义时不报错,而到使用时就报错了呢?如果是未知数据类型,应该定义时就通不过了呀,我在网上见到有人问过这样的问题,现象和我是一样的。真是百思不得其解,急死人了。对了,你哪个Shlobj是个什么东东?我#include<Shlobj.h>后还说是未知类型。如果你能给我一个能正常编译通过的例程,可就真是救我(和其他弟兄们)于水深火热之中了。多谢了!拜托了!
      

  3.   


    Using the Active Desktop Object
    This article contains information on the ActiveDesktop object that is part of the Microsoft&reg; Windows&reg; Shell API. This object, through its IActiveDesktop interface, enables you to add, remove, and change items on the desktop. Overview of the Active Desktop Interface
    The Active Desktop is a feature of Microsoft Internet Explorer 4.0 that enables you to include HTML documents and items (such as ActiveX&reg; Controls and Java applets) directly to your desktop. The IActiveDesktop interface, which is part of the Windows Shell API, is used to programmatically add, remove, and modify the items on the desktop. Active Desktop items can also be added using a Channel Definition Format (CDF) file. Accessing the Active Desktop
    To access the Active Desktop, a client application would need to create an instance of the ActiveDesktop object (CLSID_ActiveDesktop) with the CoCreateInstance function and retrieve a pointer to the object's IActiveDesktop interface. The following sample shows how to retrieve a pointer to the IActiveDesktop interface. HRESULT hr;
    IActiveDesktop *pActiveDesktop;//Create an instance of the Active Desktop
    hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
                IID_IActiveDesktop, (void**)&pActiveDesktop);//Insert code to call the IActiveDesktop methods// Call the Release method
    pActiveDesktop->Release();
    Adding a Desktop Item
    There are three methods you can use to add a desktop item: IActiveDesktop::AddDesktopItem, IActiveDesktop::AddDesktopItemWithUI, and IActiveDesktop::AddUrl. Each desktop item added to the Active Desktop must have a different source URL. The IActiveDesktop::AddDesktopItemWithUI and IActiveDesktop::AddUrl both provide the option to display the various user interfaces that can be displayed before adding a desktop item to the Active Desktop. The interfaces verify whether users want to add the desktop item to their Active Desktop. The interfaces also notify users of any security risks that are warranted by the URL security zone settings, and they ask users if they would like to create a subscription for this desktop item. Both methods also provide a way of suppressing the user interfaces. The IActiveDesktop::AddDesktopItem method requires a call to IActiveDesktop::ApplyChanges in order to update the registry. For the IActiveDesktop::AddDesktopItemWithUI, the client application must immediately release the IActiveDesktop interface and then use the CoCreateInstance function to retrieve an interface to an instance of the ActiveDesktop object that includes the newly added desktop item. The IActiveDesktop::AddDesktopItem method adds the specified desktop item to the Active Desktop without any user interface, unless the URL security zone settings prevent it. If the URL security zone settings do not allow the desktop item to be added without prompting the user, the method fails. IActiveDesktop::AddDesktopItem also requires a call to IActiveDesktop::ApplyChanges in order to update the registry. The following sample demonstrates how to add a desktop item with the IActiveDesktop::AddDesktopItem method. HRESULT hr;
    IActiveDesktop *pActiveDesktop;
    COMPONENT compDesktopItem;//Create an instance of the Active Desktop
    hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
                IID_IActiveDesktop, (void**)&pActiveDesktop);// Initialize the COMPONENT structure
    compDesktopItem.dwSize = sizeof(COMPONENT);// Insert code that adds the information about the desktop item to the COMPONENT structure// Add the desktop item
    pActiveDesktop->AddDesktopItem(&compDesktopItem,0);// Save the changes to the registry
    pActiveDesktop->ApplyChanges(AD_APPLY_ALL);Enumerating the Desktop Items
    To enumerate the desktop items currently installed on the Active Desktop, the client application needs to retrieve the total number of desktop items installed using the IActiveDesktop::GetDesktopItemCount method and then creating a loop that retrieves the COMPONENT structure for each desktop item by calling the IActiveDesktop::GetDesktopItem method using the desktop item index. The following sample demonstrates one way to enumerate the desktop items. HRESULT hr;
    IActiveDesktop *pActiveDesktop;
    COMPONENT compDesktopItem;
    int intCount;
    int intIndex = 0;//Create an instance of the Active Desktop
    hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
                IID_IActiveDesktop, (void**)&pActiveDesktop);pActiveDesktop->GetDesktopItemCount(&intCount,0);compDesktopItem.dwSize = sizeof(COMPONENT);while(intIndex<=(intCount-1))
    {
        //get the COMPONENT structure for the current desktop item
        pActiveDesktop->GetDesktopItem(intIndex, &compDesktopItem,0);    //Insert code that processes the structure    //Increment the index
        intIndex++;    //Insert code to clean-up structure for next component
    }// Call the Release method
    pActiveDesktop->Release();///////////////////////////////////////////////////////////////////////
    Requirements 
      Version 4.71 and later of Shell32.dll  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later). 
      Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later). 
      Header: Declared in Shlobj.h. 
    ///////////////////////////////////////////////////////////////////////
      

  4.   

    不是的、不是的、不是的。现在不是使用中的问题,而是根本连  编译  都通不过, 就像是在使用一个未知的数据类型。好像是少了什么头文件,我包含了以下头文件,可还是不行。它X的,不会是操作系统的问题吧? 遇到这种现象的可不只我一个人。还望各位大侠指点迷津。#include <atlconv.h>
    #include <windows.h>
    #include <WININET.H >
    #include <afxdisp.h>        
    #include <comcat.h>
    #include <olectl.h>#include <shellapi.h>
    #include <comdef.h>
    #include <shlobj.h>
      

  5.   

    为了你这个问题,可真把我累坏了,在看到shlobj.h时,还以为定义宏_WINNINET,不过试过之后也不行。请在你的Afxstd.h文件后面中加入#import "D:\\winnt\\system32\\Shell32.dll"。当然要换成你的Shell32.dll所在路径了。到于shlobj.h头文件则要不要都可以了。反正我是不要它了!如果还不行,把源码发到我的信箱让我看一下:
    [email protected]
      

  6.   

    yyz_xyz(众众)你好。源码给你发去了,请帮忙看一下,源码写的有问题,主要是因为本来我们公司是不能发信时带附件的(服务器装有什么软件,怕公司源码外泄),所以我今天只是随便写了一段试一下,没想到竟发出去了。不过这段代码多少还是能代表点问题的。对了,我发现#import"..\\Shell32.dll"在98下不可用,说什么装入失败, 2000下可以。