学习Com[二]

看了看MSDN里的一个关于IActiveDesktop例子:

// ActiveDesktopTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Objbase.h>

#include <Unknwn.h>
#include <Shlobj.h>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{

    HRESULT hr = NULL;
   
    CoInitialize(NULL);

    IActiveDesktop *pActiveDesktop;

    //Create an instance of the Active Desktop
    hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
        IID_IActiveDesktop, (void**)&pActiveDesktop);

   
    WCHAR   wszWallpaper [MAX_PATH];
    if (SUCCEEDED(hr))
    {
        pActiveDesktop->GetWallpaper(wszWallpaper, MAX_PATH, 0);

        std::wcout << L"Wallpaper path is:\n    " << wszWallpaper << std::endl;
    }

    pActiveDesktop->Release();

    CoUninitialize();
    return 0;
}

在过程中同样出现了很多人遇到的编译不过的问题, 然后在stdafx.h 头文件里添加:

#include <Windows.h>
#include <wininet.h>
#include <stdio.h>

运行结果:

Untitled

 


作者:GangWang
出处:http://www.cnblogs.com/GnagWang/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 
原文地址:https://www.cnblogs.com/GnagWang/p/1773222.html