我有一些C#COM Api例子可以工作,但在轉換爲F#時失敗。F#&COM api向下轉換問題
的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#與COM Apis通常與C#一起使用,並對這些類型轉換有一些提示?
非常感謝!
https://docs.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/functions/do-bindings –
@HansPassant這只是一個鏈接到'做'綁定... – s952163
它具體談到你必須使用的屬性來支持單線程的COM服務器。 –