昨天晚上写COM组件时突然碰到创建一个COM对象时,返回0x80040154,没有注册类型...搞得一头雾水.检查了创建函数,参数,GUID,注册表中的各项都正常.... 最后没辙了,只能新建一个COM工程试试,结果也是一样的(在同一个工程中测试).后来又新建了一个测试工程,也重新编译COM工程,结果却返回E_NOINTERFACE,晕啊.创建的对象明明支持这个接口的啊.我追踪到ATL的代码里,发现我查询的接口确实找到了,但最后还是返回E_NOINTERFACE. 经过几次调试,发现老是查询IMarshaling等几个与列集有关的接口,f却总找不到....后来在网上找到了一篇文章,找明白了一些. 参考:http://blogs.msdn.com/oldnewthing/archive/2004/12/13/281910.aspx
Why do I get E_NOINTERFACE when creating an object that supports that interface?
I've seen a few questions from people who call
the CoCreateInstance
function,
asking for an interface that they know the object supports,
yet receiving error E_NOINTERFACE
.
What's going on?
You're seeing
the same problem as the missing IMarshal,
just from the other side.
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 E_NOINTERFACE
, because the marshalling interface
is missing.
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.
Published
Monday, December 13, 2004 8:51 AM
by
oldnewthing
Filed under: Code
------------------------------
后来我看了下我的测试工程是/MDd,而COM工程的线程模型是Free,改成Apartment就好了.解释如上.但我愚钝,还是一知半解,五一好好钻研下这两个问题:
1.没有注册类型
2.E_NOINTERFACE
posted on 2008-04-29 11:35
冰风谷 阅读(4764)
评论(0) 编辑 收藏 引用 所属分类:
存疑待解 、
编程中的贝壳