【问题标题】:Outlook COM: Invoke OpenSharedItem via late bindingOutlook COM:通过后期绑定调用 OpenSharedItem
【发布时间】:2015-02-13 15:57:14
【问题描述】:

namespaceObjType 的返回类型是 System.__ComObject,无法对其调用 InvokeMember("OpenSharedItem", ...)。 您需要如何使用后期绑定技术调用此方法? 我看到的唯一区别是 Session 属性的返回对象类型只是一个接口而不是真正的 COM 类。

代码示例:

object outlookApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
Type outlookAppType = outlookApp.GetType();
object templateObj = null;
System.IO.File.Copy(templateName, temporaryFileName, true);
object namespaceObj = outlookAppType.InvokeMember("Session", System.Reflection.BindingFlags.GetProperty, null, outlookApp, new object[0]);
if(namespaceObj != null)
{
  Type namespaceObjType = namespaceObj.GetType();
  // Exception on the next line of code
  templateObj = namespaceObjType.InvokeMember("OpenSharedItem", System.Reflection.BindingFlags.InvokeMethod, null, outlookApp, new object[] { temporaryFileName });
}

执行后的异常是:未知名称。 (来自 HRESULT 的异常:0x80020006 (DISP_E_UNKNOWNNAME))

【问题讨论】:

    标签: c# com outlook late-binding


    【解决方案1】:

    你需要传递一个命名空间对象而不是outlookApp:

    namespaceObjType.InvokeMember("OpenSharedObject", System.Reflection.BindingFlags.InvokeMethod, null, namespaceObj, new object[] { temporaryFileName });
    

    无论如何,命名空间类不提供 OpenSharedObject 模式。

    您对OpenSharedItem 方法感兴趣吗?

    【讨论】:

    • 确实,我提到了 OpenSharedItem 并且已经修复了条目。此外,outlookApp 确实应该是 namespaceObj。谢谢您的帮助。现在可以了。
    猜你喜欢
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2016-02-29
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多