关于IActiveDesktop接口的问题

zlcad 2000-09-20 10:58:00
我在程序中要使用IActiveDesktop接口来控制桌面对象,编译如下语句时出错
IActiveDesktop *pActiveDesktop;
//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);


error C2027: use of undefined type 'IActiveDesktop'
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\Comdef.h(507) : see declaration of 'IActiveDesktop'
其中头文件"Comdef.h"已包含了IActiveDesktop的定义,不知怎么还出现未定义类型错误?
...全文
210 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rigel 2001-11-21
  • 打赏
  • 举报
回复
huangdong(hmz),高手!
我大概试了一下,应该可以。
作者加分!他不加我另开帖子给你加分!
huangdong 2001-11-01
  • 打赏
  • 举报
回复
Step 1:
Add head files in stdafx.h like this:
...
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include "wininet.h" //you should Add
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxconv.h> //you should Add
...





Step 2:
#include "Shlobj.h"
HRESULT hr;
USES_CONVERSION;
IActiveDesktop *pActiveDesktop;

hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr==S_OK){
LPCWSTR m_ActiveWallpaper=T2W(m_wallpaper);
hr=pActiveDesktop->SetWallpaper(m_ActiveWallpaper,NULL);
if(hr==S_OK)pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
}
ray2_ls 2001-11-01
  • 打赏
  • 举报
回复
听课,up一下
蒋晟 2001-10-28
  • 打赏
  • 举报
回复
PRB: ActiveDesktop Compilation Errors Under Visual C++ 6.0 MFC
ID: Q196342


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01sp1, 4.01sp2, 5.0
Microsoft Visual Studio 6.0

--------------------------------------------------------------------------------


SYMPTOMS
Under Visual C++ 6.0 Microsoft Foundation Classes (MFC), compiling code related to the IActiveDesktop interface will fail with multiple errors, including an "undeclared identifier" for LPACTIVEDESKTOP.

Note that this occurs specifically when compiling an MFC program using Visual C++ 6.0. There is no report of the problem occurring in previous versions of MFC or in the general Visual C++ 6.0 case where C or C++ programs are being compiled.



CAUSE
When an MFC application includes the Stdafx.h header file, the file *\Vc98\Mfc\Include\Afxdisp.h is included by default. Within Afxdisp.h the file Shlobj.h (required for ActiveDesktop) is included. But at this point, Wininet.h has not been included, so certain portions of Shlobj.h are not correctly initialized for ActiveDesktop support.

The inclusion of Shlobj.h by Afxdisp.h also sets a variable preventing Shlobj.h from being included twice. Later, when an MFC application explicitly and correctly includes Wininet.h followed by Shlobj.h, the previously set variable prevents the second Shlobj.h inclusion and also prevents critical ActiveDesktop definitions, such as for LPACTIVEDESKTOP, from being made.



RESOLUTION
Add a #include for the Wininet.h header to the Stdafx.h precompiled header file, just above the Afxdisp.h include. Here's an example of Stdafx.h:


// stdafx.h : include file for standard system include files,

...

#include <wininet.h>
#include <afxdisp.h> // MFC Automation classes

...

#endif //!defined(AFX_STDAFX_H__D5E466A9...
After correcting Stdafx.h, rebuild the entire project to ensure that the precompiled header is re-compiled.

Additional query words:

Keywords : kbActiveDesktop kbIE400 kbIE401 kbVC600 kbIE401sp1 kbIE500
Version : WINDOWS:4.0,4.01,4.01sp1,4.01sp2,5.0dp1,6.0
Platform : WINDOWS
Issue type : kbprb
Technology :


Last Reviewed: April 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
ray2_ls 2001-10-27
  • 打赏
  • 举报
回复
up
huangdong 2001-10-27
  • 打赏
  • 举报
回复
请问你的平台是win9x吗?
Holly 2000-09-26
  • 打赏
  • 举报
回复

#include <wininet.h>
#include <afxdisp.h> // MFC Automation classes
Holly 2000-09-21
  • 打赏
  • 举报
回复
不是Comdef.h而是shlobj.h
Comdef.h只有一个提前声明,没有接口的内容,所以会出现上面的错误!
zlcad 2000-09-21
  • 打赏
  • 举报
回复
#include <Shlobj.h>
#include <Shlguid.h>
都试过,IActiveDesktop *pActiveDesktop;CoCreateInstance(...);能通过,但
pActiveDesktop->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE );却又出错!

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧