首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >希望将对象类型数据从一个VSTO addin项目发送到另一个VSTO addin项目

希望将对象类型数据从一个VSTO addin项目发送到另一个VSTO addin项目
EN

Stack Overflow用户
提问于 2022-07-19 13:41:22
回答 2查看 33关注 0票数 0

我正在编写Outlook外接程序,其中我希望将数据从一个outlook外接程序项目发送到另一个outlook项目。但是,当我尝试用参数中的对象类型数据调用另一个项目的函数时,它将抛出“无法将'System.Runtime.Remoting.Proxies.__TransparentProxy‘类型的对象强制转换为在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo中键入的对象”错误。。

这是供您参考的代码。

代码语言:javascript
运行
复制
                 public IProfileAttribute[] profileAttributes= null;
                 Outlook.Application outlookApp = new Outlook.Application();
                 this.profileAttributes = new FilingNotifiableIpmlementation().FilingNotification(); // to fill the object 
                object destAddinName = "Tikit.CarpeDiem.AddIn.Outlook";
                Office.COMAddIn destAddIn = outlookApp.COMAddIns.Item(ref destAddinName)                                
                destAddIn.Object.FilingNotification(this.profileAttributes);

FilingNotification()是我们想要调用的Tikit.CarpeDiem.AddIn.Outlook方法,这个项目和this.profileAttributes是对象数组。

如果参数类型为string或int,则流非常适合Outlook项目,但如果参数是对象类型,则会引发错误。

FilingNotification()方法在Tikit.CarpeDiem.AddIn.Outlook项目中的实现。

代码语言:javascript
运行
复制
public void FilingNotification(IProfileAttribute[] profileAttributesList)
    {
        if (profileAttributesList != null)
        {
            var x = profileAttributesList;
        }
        else
        {
            string y = "Try again";
        }
    }

有人能帮我这个忙吗。我被困在这里面两天了。这会很有帮助的。提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2022-07-19 15:36:08

与其传递.Net对象,不如让它实现COM接口并将其作为接口传递:

代码语言:javascript
运行
复制
var obj = new MyBlah();
destAddIn.Object.FilingNotification(obj as IBlah);
...
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IBlah
{
    void DoBlah();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class MyBlah: StandardOleMarshalObject, IBlah
{
    public void DoBlah() 
    {
       //todo
    };
}
票数 0
EN

Stack Overflow用户

发布于 2022-07-19 15:36:18

您可以按照这种方式传递标量数据类型。如果要在两个实体之间传递对象,则需要实现双方都知道的接口。在演练:从VBA调用VSTO外接程序中的代码。文章中阅读更多有关这方面的内容。例如:

代码语言:javascript
运行
复制
[ComVisible(true)]
public interface IAddInUtilities
{
    void ImportData();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInUtilities : IAddInUtilities
{
    // This method tries to write a string to cell A1 in the active worksheet.
    public void ImportData()
    {
        // implementation
    }
}

此外,您还可以考虑使用任何可用于基于.net的应用程序(如远程处理或WCF )的标准机制,有关更多信息,请参见基本WCF编程

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73038057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档