COM 类型地狱。 Ghost编译器重写我的代码?
我已经研究一个问题一个多星期了,所以我可能是盲目的、沮丧的或者只是单纯的疯子。请原谅我,但是......
我的类有这个成员:
IDevicePtr devicePtr
一个函数需要 (IDevicePtr * ptr)
作为参数。
我无法将 devicePtr 传递给它,自然原因:
cannot convert parameter 2 from 'IDevicePtr' to 'IDevicePtr *
但是...
我也无法将 &devicePtr 传递给它:
compiler screams: cannot convert parameter 2 from 'IDevice **' to 'IDevicePtr *'
“Idevice**”来自哪里?当我有 IDevicePtr 对象时,如何满足“IDevicePtr *”函数参数要求?
抱歉让您感到沮丧。上周我尝试在不使用 ATL 或 MFC 的情况下拦截一个 COM 事件。没有成功。我无法找到曾经做过类似事情的活着的人。
I've been working on a problem for over a week, so I may be blind, frustrated or just plain nuts. Please forgive me, but....
My class has this member:
IDevicePtr devicePtr
a function wants (IDevicePtr * ptr)
as a parameter.
I can't pass devicePtr to it, natural reasons:
cannot convert parameter 2 from 'IDevicePtr' to 'IDevicePtr *
BUT...
i also can't pass &devicePtr to it:
compiler screams: cannot convert parameter 2 from 'IDevice **' to 'IDevicePtr *'
Where did "Idevice**" come from? How can I satisfy the "IDevicePtr *" function parameter requirements when I have an IDevicePtr object?
Sorry for the frustration. I've spent the last week trying to intercept one COM event without using ATL or MFC. No success. I haven't been able to locate a living person who ever did something like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_COM_SMARTPTR_TYPEDEF
定义了一个指针包装类 - 您可以将其视为基本上typedef IDevice *IDevicePtr
,除了您的IDevicePtr
自动释放和自动释放参考。您不应该传递
IDevicePtr *
。仅当您获取引用时,才传递IDevice *
并将其包装在IDevicePtr
中,或者如果您想返回,则传递IDevice **
-通过引用(您可以使用IDevicePtr
的地址来获取IDevice **
)。不要尝试使用IDevicePtr *
进行引用返回;由于operator&
重载,这将失败(这就是您所看到的问题)。_COM_SMARTPTR_TYPEDEF
defines a pointer wrapper class - you can think of it as basicallytypedef IDevice *IDevicePtr
, except that yourIDevicePtr
auto-releases and auto-references.You should not be passing
IDevicePtr *
s around. Pass aroundIDevice *
and wrap it in aIDevicePtr
only if you take a reference, or pass aIDevice **
if you want to return-by-reference (you can take the address of anIDevicePtr
to get anIDevice **
). Do not attempt to use aIDevicePtr *
for return-by-reference; this will fail (this is the problem you are seeing) because of thatoperator&
overload.