﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-xgzpan-随笔分类-存疑待解</title><link>http://www.cppblog.com/xgzpan/category/2506.html</link><description>一步一个脚印</description><language>zh-cn</language><lastBuildDate>Wed, 21 May 2008 16:14:52 GMT</lastBuildDate><pubDate>Wed, 21 May 2008 16:14:52 GMT</pubDate><ttl>60</ttl><item><title>一个COM对象明明支持一个接口，创建时却返回E_NOINTERFACE的问题</title><link>http://www.cppblog.com/xgzpan/archive/2008/04/29/48405.html</link><dc:creator>冰风谷</dc:creator><author>冰风谷</author><pubDate>Tue, 29 Apr 2008 03:35:00 GMT</pubDate><guid>http://www.cppblog.com/xgzpan/archive/2008/04/29/48405.html</guid><wfw:comment>http://www.cppblog.com/xgzpan/comments/48405.html</wfw:comment><comments>http://www.cppblog.com/xgzpan/archive/2008/04/29/48405.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xgzpan/comments/commentRss/48405.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xgzpan/services/trackbacks/48405.html</trackback:ping><description><![CDATA[<span style="color: #700000;">&nbsp;&nbsp;&nbsp; 昨天晚上写COM组件时突然碰到创建一个COM对象时，返回0x80040154,没有注册类型...搞得一头雾水.检查了创建函数，参数，GUID,注册表中的各项都正常....</span><br style="color: #700000;"><span style="color: #700000;">&nbsp;&nbsp;&nbsp; 最后没辙了，只能新建一个COM工程试试，结果也是一样的（在同一个工程中测试）.后来又新建了一个测试工程，也重新编译COM工程，结果却返回E_NOINTERFACE，晕啊.创建的对象明明支持这个接口的啊.我追踪到ATL的代码里，发现我查询的接口确实找到了，但最后还是返回E_NOINTERFACE. 经过几次调试，发现老是查询IMarshaling等几个与列集有关的接口,f却总找不到....后来在网上找到了一篇文章，找明白了一些.</span><br style="color: #700000;"><span style="color: #700000;">　参考：http://blogs.msdn.com/oldnewthing/archive/2004/12/13/281910.aspx</span><br style="color: #700000;"><span style="color: #700000;">&nbsp;&nbsp;&nbsp; </span><br style="color: #700000;">
<h2 style="color: #700000;">Why do I get E_NOINTERFACE when creating an object that supports that interface?</h2>
<p style="color: #700000;">
I've seen a few questions from people who call
<a href="http://msdn.microsoft.com/library/en-us/com/htm/cmf_a2c_1nad.asp">
the <code>CoCreateInstance</code> function</a>,
asking for an interface that they know the object supports,
yet receiving error <code>E_NOINTERFACE</code>.
What's going on?
</p>
<p style="color: #700000;">
You're seeing
<a href="http://blogs.msdn.com/oldnewthing/archive/2004/02/20/77120.aspx">
the same problem as the missing IMarshal</a>,
just from the other side.
</p>
<p style="color: #700000;">
If your threading model is incompatible with the threading model
of the object you're creating, then COM marshalling kicks in.
And if the marshalling stuff isn't there, the error that comes
out is <code>E_NOINTERFACE</code>, because the marshalling interface
is missing.
</p>
<p style="color: #700000;">
A common source of this is attempting to use COM objects provided
by the shell from a multi-threaded apartment.  Remember that shell
COM objects are, for the most part, apartment-threaded, not
free-threaded.
If you want to use shell objects, you should do so from single-threaded
apartments.
</p>
<span style="color: #700000;">
Published
Monday, December 13, 2004 8:51 AM
by
</span><a style="color: #700000;" href="http://blogs.msdn.com/user/Profile.aspx?UserID=2905" id="ctl00___ctl00___ctl01___Entry___AuthorLink">oldnewthing</a><span style="color: #700000;">
</span><span style="color: #700000;" id="ctl00___ctl00___ctl01___Entry___InlineTagEditorPanel">Filed under: <a href="http://blogs.msdn.com/oldnewthing/archive/tags/Code/default.aspx" rel="tag">Code</a><br><br><br>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br><br>&nbsp;&nbsp;&nbsp; 后来我看了下我的测试工程是/MDd,而COM工程的线程模型是Free，改成Apartment就好了.解释如上.但我愚钝，还是一知半解，五一好好钻研下这两个问题：<br><br>&nbsp;&nbsp;&nbsp; １.没有注册类型<br><br>&nbsp;&nbsp;&nbsp; ２.E_NOINTERFACE</span><span style="font-size: 36pt; color: #700000;"><span style="font-size: 24pt;"><span style="font-size: 14pt;"><span style="font-size: 12px;"></span></span><span style="font-size: 12px;"></span></span><span style="font-size: 12px;"></span></span><span style="font-size: 12px; color: #700000;"></span><span style="text-decoration: underline; color: #700000;"></span> <img src ="http://www.cppblog.com/xgzpan/aggbug/48405.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xgzpan/" target="_blank">冰风谷</a> 2008-04-29 11:35 <a href="http://www.cppblog.com/xgzpan/archive/2008/04/29/48405.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>工作线程向界面线程发消息的问题</title><link>http://www.cppblog.com/xgzpan/archive/2006/08/22/11558.html</link><dc:creator>冰风谷</dc:creator><author>冰风谷</author><pubDate>Tue, 22 Aug 2006 02:50:00 GMT</pubDate><guid>http://www.cppblog.com/xgzpan/archive/2006/08/22/11558.html</guid><wfw:comment>http://www.cppblog.com/xgzpan/comments/11558.html</wfw:comment><comments>http://www.cppblog.com/xgzpan/archive/2006/08/22/11558.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xgzpan/comments/commentRss/11558.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xgzpan/services/trackbacks/11558.html</trackback:ping><description><![CDATA[　　这几天在做一个网络诊断的工具。用到两个线程：<br />　　界面线程：界面是一个对话框。在对话框上有一个进度条。<br />　　工作线程：执行检测的工作。并把对各项的检测结果以自定义消息发送给界面线程，让它呈现出来...<br /><br />　　我定义了一个消息：#define WM_SETPROGRESS WM_USER + 105  <font style="BACKGROUND-COLOR: #ffffff"><font color="#008000">//设置进度条的进度</font><br /></font>　　然后每检测完一项后，用PostMessage向界面线程发送WM_SETPROGRESS消息。就出现不正常的现象。比如我已检测完一类的进度，现在想检测另一类的，所以我要重新设置一个范围(SetRange(0,100))和一个新的位置(SetPos(0))，但好像并没有执行。还是前一类检测完后的进度。<br /><br />　　如果在工作线程中用一个循环不断的post消息，结果只处理了一小部分的消息。即：<br />　　[工作线程中]<br />        for(int i=1;i&lt;=100;i++)<br />       {<br />               PostMessage(m_hWnd,WM_SETPROGRESS,i,0);<br />       }<br /><br />   　用SendMessage代替PostMessage，处理得更好一些。因为可以看到进度条的进度更长些，但也只显示了不到一半的进度...<br /><br />　　如果把对话框对象指针传递给工作线程，在那里调用SetPos，进度条就工作的很好...<img src ="http://www.cppblog.com/xgzpan/aggbug/11558.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xgzpan/" target="_blank">冰风谷</a> 2006-08-22 10:50 <a href="http://www.cppblog.com/xgzpan/archive/2006/08/22/11558.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>