本文介绍了如何使用Marshal.QueryInterface?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Word文档中某些嵌入对象的工作。较早的海报告诉我,这是不是直线前进。这里是链接答案的摘录:
So I am interested in exposing which interface the object is implementing. The closest I could find is here. The code so far is below and any help with the Marshal.QueryInterface is greatly appreciated.
// Opening the word document
object missing = Type.Missing;
this.document = wordApp.Documents.Open(
ref fn, ref confirmConversions, ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
foreach (Microsoft.Office.Interop.Word.InlineShape inlineShape in this.document.InlineShapes)
{
if (inlineShape.OLEFormat.ProgID != null)
{
switch (inlineShape.OLEFormat.ProgID)
{
// This is a pdf file
case "AcroExch.Document.7":
//Marshal.QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
break;
default:
break;
}
}
}
解决方案
Marshal.QueryInterface
shouldn't be necessary - if you take a COM object and cast it to a COM interface type, .NET does the QueryInterface
call for you. That is, you can write: IPersistStorage persist = (IPersistStorage) obj;
However it's not clear to me which object in the code implements IPersistStorage
, IPersistStreamInit
etc.
这篇关于如何使用Marshal.QueryInterface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!