PatternMatching
PatternMatching

Reputation: 466

Excel COM add-in DLL's - Can I use directly from C#?

Forgive the question if the answer is obvious. I am certainly no COM expert.

So I have two DLL's that are typically used as add-ins to Excel (loaded directly after Excel is opened programatically). I assume they are COM. How can I tell if they are unmanaged C++ DLL's?

Is it possible for me to use as references in a C# project and call the methods directly instead of trying to go through Excel? Is there any trick to doing this? Is this the best way to go about utilizing these methods?

Performance is a big thing for me and trying to call the DLL code through Excel is very painful. I'm not sure if Excel is the offender or not but obviously eliminating as many middleman touches as possible is ideal.

Upvotes: 0

Views: 531

Answers (1)

Ken Brittain
Ken Brittain

Reputation: 2265

I would suggest finding out out if they are indeed COM DLLs first. You can use a depends .exe to see if the DLL exports some of the expected COM functions: DllGetClassObject and DllCanUnloadNow are good indicators. If so you might be able to import the DLL directly into your project using Visual Studio. My gut tells me that approach hinges upon the COM object supporting OLE Automation so your mileage may vary there.

Otherwise you probably just have a plain old DLL. Again, find out what function are exported, and use p/invoke for guidance on how to get the signature right.

Upvotes: 1

Related Questions