我需要IMessage接口.在C#我可以写
CDO.Message oMsg = new CDO.Message(); // ok
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在F#中这样做时
let oMsg = new CDO.Message()
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
'new'不能用于接口类型.考虑使用对象表达式'{new ... with ...}'.
如何解决这个问题呢?
我使用mshtml进行html解析.(版本7.0.3300.0,C:\ Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll).
HTMLDocumentClass有一个write方法,所以我使用它,但它引发了与ErrorCode的ComException:-2147352571和消息:类型不匹配.它是什么原因?如果不使用HTMLDocumentClass的write方法,他们为什么定义?
HTMLDocumentClass getHTMLDocument(string html)
{
HTMLDocumentClass doc = new HTMLDocumentClass();
doc.write(new object[] { html }); // raises exception
doc.close();
return doc;
}
HTMLDocumentClass getHTMLDocument2(string html)
{
HTMLDocumentClass doc = new HTMLDocumentClass();
IHTMLDocument2 doc2 = (IHTMLDocument2)doc;
doc2.write(new object[] { html });
doc2.close();
return doc;
}
Run Code Online (Sandbox Code Playgroud)