📄 subject_27360.htm
字号:
<p>
序号:27360 发表者:daji 发表日期:2003-01-10 16:21:15
<br>主题:一个调用COM的菜问题
<br>内容: WCHAR warpaper[50];<BR> CString warPaperPath;<BR> HRESULT hr; <BR> IActiveDesktop* pIAD;<BR> // 1. 初始化COM库(让Windows加载DLLs)。通常是在程序的InitInstance()中调用<BR> // CoInitialize ( NULL )或其它启动代码。MFC程序使用AfxOleInit()<BR> CoInitialize ( NULL );<BR><BR> hr = CoCreateInstance(CLSID_ActiveDesktop,<BR> NULL,<BR> CLSCTX_INPROC_SERVER,<BR> IID_IShellLink,<BR> (void**) &pIAD);<BR> if (SUCCEEDED(hr))//如果返回成功,则处理<BR> {<BR> hr = pIAD->GetWallpaper( warPaperPath, 50, 0 );<BR> if(SUCCEEDED(hr))<BR> {<BR> MessageBox(wszWallpaper);<BR> }<BR> else<BR> {<BR> MessageBox("调用接口方法错误");<BR> }<BR> <BR> pIAD->Release();//通知COM对象,不在使用它<BR> }<BR> else<BR> {<BR> MessageBox("无法获取COM指针");<BR> }<BR><BR>编译气提示:<BR>G:\foot\ConToAdo\ConToAdoDlg.cpp(326) : error C2027: use of undefined type 'IActiveDesktop'<BR> d:\program files\microsoft visual studio\vc98\include\comdef.h(507) : see declaration of 'IActiveDesktop'<BR>G:\foot\ConToAdo\ConToAdoDlg.cpp(326) : error C2227: left of '->GetWallpaper' must point to class/struct/union<BR>G:\foot\ConToAdo\ConToAdoDlg.cpp(329) : error C2065: 'wszWallpaper' : undeclared identifier<BR>G:\foot\ConToAdo\ConToAdoDlg.cpp(336) : error C2027: use of undefined type 'IActiveDesktop'<BR> d:\program files\microsoft visual studio\vc98\include\comdef.h(507) : see declaration of 'IActiveDesktop'<BR>G:\foot\ConToAdo\ConToAdoDlg.cpp(336) : error C2227: left of '->Release' must point to class/struct/union<BR>Error executing cl.exe.<BR><BR>ConToAdo.exe - 5 error(s), 1 warning(s)<BR><BR>为什么呢?<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2003-01-10 16:35:50
<br>内容:只能是猜想:<BR><BR>你包含了头文件了吗?<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:daji 回复日期:2003-01-10 16:43:16
<br>内容:什么头文件?<BR>哪个?<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:ax 回复日期:2003-01-13 09:08:00
<br>内容:stdafx.h文件改为:<BR>#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers<BR><BR>#include <afxwin.h> // MFC core and standard components<BR>#include <afxext.h> // MFC extensions<BR>#include "wininet.h"<BR>#include <afxdisp.h> // MFC Automation classes<BR>#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls<BR>#ifndef _AFX_NO_AFXCMN_SUPPORT<BR>#include <afxcmn.h> // MFC support for Windows Common Controls<BR>#endif // _AFX_NO_AFXCMN_SUPPORT<BR><BR>#include <afxconv.h><BR>#include <comdef.h><BR><BR><BR>你的程序改为:<BR>WCHAR warpaper[50];<BR> CString warPaperPath;<BR> HRESULT hr; <BR> IActiveDesktop* pIAD;<BR> // 1. 初始化COM库(让Windows加载DLLs)。通常是在程序的InitInstance()中调用<BR> // CoInitialize ( NULL )或其它启动代码。MFC程序使用AfxOleInit()<BR> CoInitialize ( NULL );<BR><BR> hr = CoCreateInstance(CLSID_ActiveDesktop,<BR> NULL,<BR> CLSCTX_INPROC_SERVER,<BR> IID_IShellLink,<BR> (void**) &pIAD);<BR> if (SUCCEEDED(hr))//如果返回成功,则处理<BR> {<BR> hr = pIAD->GetWallpaper( warpaper, 50, 0 );<BR> warPaperPath = warpaper;<BR> <BR> if(SUCCEEDED(hr))<BR> {<BR> MessageBox(wszWallpaper);<BR> }<BR> else<BR> {<BR> MessageBox("调用接口方法错误");<BR> }<BR> <BR> pIAD->Release();//通知COM对象,不在使用它<BR> }<BR> else<BR> {<BR> MessageBox("无法获取COM指针");<BR> }<BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:daji 回复日期:2003-01-13 09:18:18
<br>内容:谢谢,原来是因为我没有 #include <afxconv.h>的原因!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:彭&nbsp;&nbsp;灏 回复日期:2003-01-13 12:44:55
<br>内容:改了旧好撒
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -