[英]System.InvalidCastException when using a COM interface
I wrote a atl COM dll, dual. 我写了一个atl COM dll,双。 And used one of its intreace X in a C# GUI proj. 并在C#GUI项目中使用了其中一个intreace X. when call XF(), I got an System.InvalidCastException, can not cast namespace.XClass to namespace.IX, QueryInterface failed: BADTYPE. 当调用XF()时,我得到一个System.InvalidCastException,无法将namespace.XClass强制转换为namespace.IX,QueryInterface失败:BADTYPE。 The call was in my own thread. 电话是我自己的话题。
If i move the code to the GUI thread, it works just fine. 如果我将代码移动到GUI线程,它可以正常工作。
Please help me with that. 请帮帮我。 Thanks a lot. 非常感谢。
COM对象通常是STA,这意味着它们只能由创建它们的线程使用
COM requires a proxy/stub to marshal the call from the thread to the thread that created the object. COM需要代理/存根来封送从线程到创建对象的线程的调用。 QI will fail if it cannot find it in the HKCR\\Interface registry key. 如果在HKCR \\ Interface注册表项中找不到它,QI将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.