我可以使用 Excel::_Application::Run 调用 C# dll 方法吗

Can I call a C# dll method using Excel::_Application::Run

我有一个用 c++ 编写的应用程序,它使用 Excel 来显示数据。我还在 vsto 中为 Excel 编写了插件。

现在我想向我的 C++ 应用程序发送有关插件点击的事件。

为了实现这一点,我用 C++ 编写了 com 接口。现在我想在 vsto c# dll 中为那个 class 设置对象,这样我就可以从我的 c++ 应用程序中调用一个方法。

Excel::_ApplicationPtr &app;

CComObject<TestEvent> *obj = new CComObject<TestEvent>;
obj->Init(this);
variant_t v = static_cast<IDispatch *>(obj);
app->Run("SetEventSinkTest", v);    

我可以从我的 C# dll 调用用 C++ 编写的 SetEventSinkTest 方法吗? 我已经从 c++ 应用程序启动了 Excel 进程,该应用程序具有用 c# 编写的 vsto 插件。我想将 Excel 加载项点击事件返回到 C++ 应用程序。

为了实现这一点,我有一个 class TestEvent 的 com 对象,其指针将在 C# vsto dll 中设置。在加载项单击事件上,我将执行 TestEvent class 中的一个函数,我想在 vsto c# 项目中设置其对象。

这在 com 和 VSTO 中可行吗

我找到了使用 Excel::_Application::Run 方法调用 Excel 插件方法 C++ 应用程序的解决方案。

要实现这一点,我们首先需要在 .net class 库中编写自动化插件。

阻止网络程序集公开此自动化插件方法。

这样我们就可以直接从c++调用自动化插件

在 Excel 中使用 C# .NET 用户定义函数 (UDF) http://www.adamtibi.net/07-2012/using-c-sharp-net-user-defined-functions-udf-in-excel