Search code examples
c#.netdllcomshell-extensions

Communicate between a COM DLL and C#


I asked a question the other day regarding overlay icons. With help, I figured out how to get that working.

Here's how an icon overlay works (as far as I understand): Before the shell draws an icon it contacts all the icon overlay handlers in the system to determine whether it should draw an overlay on the that particular icon.

My setup:
I have a registered Shell Extension (Icon Overlay Handler) that I want to use to display icon overlays. Also, I have a .NET application (C#) that will write to a database (SQLite, most likely) with the names, etc. of all the files and folders I want to display an overlay on.

My problem is:
How do I get the Shell Extension (I think its basically a COM DLL) to call back into my .NET application? Or is that overkill and should I just have the Shell Extension read from the database directly?

Possible solutions?

  1. Have the Shell Extension (icon overlay handler) read the database and determine whether to show overlay.
  2. Have the Shell Extension call back into a .NET application to determine whether to show the overlay.

I hope this makes sense, if not, I'll try to elaborate.


Solution

  • A COM DLL cannot talk to .NET assembly directly. You might need to expose your .NET assembly as COM object and talk to this COM object instead. But this might in fact be an overkill in your scenario. Another option would be to expose the functionality that talks to the database in your .NET assembly as some interoperable service (WCF?) that might be called from the shell etension.