- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 Word 文档中的一些嵌入对象。较早的张贴者告诉我,这不是直截了当的。以下是链接答案的摘录:
"As I mentioned earlier, utilizing the embedded object's programming model to perform the save is something of a shortcut. There is a more involved solution that will work with any embedded object. In order for the object to be embedded in the first place, it must support one of the COM IPersist interfaces (i.e IPersistStorage, IPersistStreamInit, IPersistFile, etc). Therefore, an embedded object can always be extracted by calling Marshal.QueryInterface on the OLEFormat.Object (to determine the appropriate persistance interface), casting accordingly and then calling the appropriate method. Depending on which persistence interface you use, you may need to call some additional methods to expose the appropriate storage over the top of a file. Also, depending on the type of embedded object, you may still need to activate the object prior to being able to successfully QueryInterface for the persistance interfaces."
所以我有兴趣公开对象正在实现的接口(interface)。我能找到的最接近的是 here .到目前为止的代码在下面,非常感谢对 Marshal.QueryInterface 的任何帮助。
// 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
不是必需的 - 如果您采用 COM 对象并将其转换为 COM 接口(interface)类型,.NET 会为您调用 QueryInterface
。也就是说,您可以这样写:IPersistStorage persist = (IPersistStorage) obj;
但是我不清楚代码中的哪个对象实现了IPersistStorage
、IPersistStreamInit
等。
关于c# - 如何使用 Marshal.QueryInterface?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5077172/
我有一个非托管 C++ 类,其中有一个 com 映射。例如: BEGIN_COM_MAP (MyClass) COM_INTERFACE_ENTRY(...) END_COM_MAP 但是现在如果
问题: 我在代理上成功调用了 CoSetProxyBlanket(如果这是正确的术语),然后我在同一个代理上调用了 QueryInterface,但我收到了 0x80070005(“拒绝访问”)的结果
如果我有 IUnknown *ptr , 我需要调用Release()在我通过ptr->QueryInterface()获得的每个界面上, 另外调用ptr->Release()当我完成 ptr ? 我
我试图找到这个问题的答案,但完全没有运气。没有关于如何使用 Marshal.QueryInterface 返回的值的文档。 (在我的情况下是“pISomething”)。它是 IntPtr 的一个实例
考虑以下代码: TMyList = class(TList, IMyList) Delphi 向我显示错误: [DCC Error] test.pas(104): E2003 Undeclared i
我写了这段代码 'use strict'; module.exports = { up: (queryInterface, Sequelize) => { }, down: (queryI
假设我有一个实现两个或多个 COM 接口(interface)的类(与 here 完全一样): class CMyClass : public IInterface1, public IInterfa
IUnknown::QueryInterface() 被传递了一个 void** 参数,表示放置检索到的接口(interface)的地址。 STDMETHOD QueryInterface(/* [i
我想将此 USB 检测器转换为 Swift 3 https://gist.github.com/zachbadgett/471d72e83fee413d0f38 但是我卡在了这条线上: let dev
我正在尝试使用 Word 文档中的一些嵌入对象。较早的张贴者告诉我,这不是直截了当的。以下是链接答案的摘录: "As I mentioned earlier, utilizing the embedd
queryInterface.removeConstraint() 的文档没有记录可以传递给 removeConstraint() 方法的 options 对象。事实上,没有记录可以传递给各种 que
我在实用程序库中遇到问题,它执行一些 COM 互操作。它保留对在调用之间使用的 COM 对象的引用。 如果所有方法都是从使用相同 COM 线程模型的线程调用的,则该类可以正常工作。 但是,如果创建 C
是否可以为使用 ATL 的类提供 QueryInterface 的实现? BEGIN_COM_MAP(CConcrete) // Defines _InternalQueryInterface C
在我的应用程序中,我通过 CreateInstance 创建了一个对象 A,该对象又创建了一个对象 B。这两个对象应该存在于同一个进程中。 现在我看到对象 B 在请求某个接口(interface)时返
以上是否可行? 我可以这样做吗: IUnknown *punk; punk->QueryInterface(IID_MyInterface, (void**)&m_pMyInterface); 我认为
我正在尝试在现有 COM 组件中构建连接点。我从 CCmdTarget 派生类,并按照 MSDN 中的描述在类声明和实现中调用 MFC 宏。组件已正确构建、链接和运行。但是,当我调试我的客户端应用程序
这个问题在这里已经有了答案: Handling CoCreateInstance return value (2 个答案) 关闭 8 年前。 设想一种情况: CComPtr pGraph; HRES
我想知道是否有更简洁的方法来编写下面的(工作)代码: uint uEnum = 0; PStore.EnumTypes(0, 0, ref uEnum); System.Reflection.Memb
IUnknown::QueryInterface() 的典型实现方式如下:为每个支持的接口(interface) ID 使用一个 if-else-if 链并执行以下操作: if( iid == __u
我明白 QueryInterface 是什么方法实际上是这样做的——它只返回一个指向特定接口(interface)的指针。但我的问题是,我为什么要使用这种方法? 我的意思是,有什么区别 QueryIn
我是一名优秀的程序员,十分优秀!