gpt4 book ai didi

F# 和 COM api 向下转换问题

转载 作者:行者123 更新时间:2023-12-02 13:35:42 24 4
gpt4 key购买 nike

我有一些 C# COM Api 示例可以工作,但在转换为 F# 时失败。

F# 代码是:

let list = api.CreateXXX() :?> XXX

C# 转换是隐式的(对象将变量定义为 XXX,然后使用 api.CreateXxxModule() 对其进行初始化,无需进一步转换。

private XXX list;
[...]
list = api.CreateXXX()

Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'ThomsonReuters.Interop.RTX.AdxRtList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{057B736E-03DF-11D4-99C8-00105AF7EDAD}' failed due to the following error: Cette interface n’est pas prise en charge (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

使用 XXXClass 而不是 XXX 进行向下转型也不起作用:

Additional information: Unable to cast COM object of type 'System.__ComObject' to class type 'XXXClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

是否有人使用过 F# 和通常与 C# 一起使用的 COM API,并且对这些类型转换有一些建议?

非常感谢!

最佳答案

将 STAThread 属性添加到主要函数中:

module Main =

[<STAThread>]
do
...

关于F# 和 COM api 向下转换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40256259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com