简体   繁体   English

使用COM接口时System.InvalidCastException

[英]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.

相关问题 使用自定义ValueConverter时Select上的System.InvalidCastException - System.InvalidCastException on Select when using custom ValueConverter 尝试实例化位于可执行文件中的COM对象时,COM Interop:System.InvalidCastException - COM Interop: System.InvalidCastException when trying to instantiate COM object located in an executable 使用datagridview时发生System.InvalidCastException - System.InvalidCastException when work with datagridview System.InvalidCastException:无法将类型为“System .__ ComObject”的COM对象强制转换为接口类型“System.Collections.IEnumerable” - System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable' 服务器上的System.InvalidCastException - System.InvalidCastException On Server System.InvalidCastException在 - System.InvalidCastException in System.InvalidCastException:尝试在 C# 中使用实体框架将对象添加到 SQL 数据库时 - System.InvalidCastException: When trying to add an object to a SQL database using Entity Framework in C# System.InvalidCastException "对象必须实现 IConvertible。" 使用 BinaryFormatter 反序列化字典时 - System.InvalidCastException "Object must implement IConvertible." when deserializing a Dictionary using a BinaryFormatter C#System.InvalidCastException:'指定的转换无效。' 将MySQL与Discord.Net一起使用时 - C# System.InvalidCastException: 'Specified cast is not valid.' When using MySQL with Discord.Net 强制转换字符时c#System.InvalidCastException - c# System.InvalidCastException when casting a char
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM