Questions about ExcelDnaUtil.Application

Apr 24, 2015 at 5:38 PM
Edited Apr 25, 2015 at 7:06 AM
Hello,

I have seen that it's possible to cast ExcelDnaUtil.Application to a dynamic variable (in C#).
After performing this cast, I wonder what is the type of my object.
What can I do whith him ?
Is it a Microsoft.Office.Interop.Excel.Application COM object ?

If you can help me to understand these concepts, it would be great.

@+
Coordinator
Apr 24, 2015 at 9:06 PM
Yes - ExcelDnaUtil.Application returns a Microsoft.Office.Interop.Excel.Application COM object. (Technically it is a .NET Runtime Callable Wrapper (RCW) that the runtime creates for the Application COM interface.)

If you reference the Microsoft.Office.Interop.Excel.dll interop assembly in your project, you can directly cast it to a variable of type Application.
Alternatively you can use it via the c# dynamic support, which automatically marshals COM calls.

-Govert
Marked as answer by SigmaPic on 4/25/2015 at 12:08 AM
Apr 25, 2015 at 7:14 AM
Edited Apr 25, 2015 at 7:15 AM
Ok, in fact it was written in the documentation, but I was not sure:
Otherwise you would reference an interop assembly that defines the COM types to your .NET project. You still get the right Application object from ExcelDnaUtil.Application, but now cast this to the type Microsoft.Office.Interop.Excel.Application and use it from there.
More information can, be foudn here:
Documentation > Using the Excel COM Automation Interfaces