0
votes

I have an application written in c++ which uses Excel to display data. Also I have written addins for Excel in vsto.

Now I want to send a event to my c++ application about addin click.

To achieve that I have written com interface in c++. And now I want to set the object for that class in vsto c# dll so that I can call a method from my c++ application.

Excel::_ApplicationPtr &app;

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

Can I call SetEventSinkTest method written in c++ from my C# dll. I have launch Excel process from c++ application which has the vsto addin written in c#. I want to get Excel addin click event back to the c++ application.

To achieve this I have a com object of class TestEvent whose pointer will be set in C# vsto dll. on addin click event I will execute a function from TestEvent class whose object I want set in vsto c# project.

Can this is possible in com and VSTO

1
THere's no such thing as a "C# DLL". You mean a managed (.NET) assembly. The C# tag is wrong. - rory.ap
@rory.ap - why not edit the title? - Rand Random
Didn't feel like it. - rory.ap
Welcome to S.O.! Have you tried to find an existing answer before posting? This link is the 1st one I saw when I Googled your title, and there are many more. Please check out "help center" -- S.O. is a place for professional (or enthusiast!) programmers to share advice when a problem's solution can't be found elsewhere; we like to see that some effort has been made in finding a solution before asking for help, so please edit your question to include details about what you've tried so far. - ashleedawg
@ashleedawg - Currently I am able to call c++ function from VBA. But I am looking similar functionality in c#. So that I dond need to modify my c++ application. - pritesh dahivelkar

1 Answers

1
votes

I found the solution to call Excel addin method c++ application using Excel::_Application::Run method.

To achieve this we first need to write automation addin in .net class library.

resister net assembly to expose this automation addin method.

with this we can directly call automation addin from c++

Using C# .NET User Defined Functions (UDF) in Excel http://www.adamtibi.net/07-2012/using-c-sharp-net-user-defined-functions-udf-in-excel