sharptooth
sharptooth

Reputation: 170499

How to detect if my COM object is being used from a .NET application?

I have a COM DLL written in Visual C++. I fully control that COM DLL code. Of course it can be consumed from both managed and unmanaged applications. I want to insert a very specific check that should only be run when the COM DLL is consumed by a .NET application.

Is there some programmatic way for my COM object to detect whether it is being consumed from a .NET application or from an unmanaged application?

Upvotes: 3

Views: 360

Answers (2)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

Two possibilities:

  1. Create a native .NET assembly wrapping the COM object and initializing it appropriately
  2. Try to detect whether your process is a .NET process and live with the problems (no mono detection, false positives, most likely invalid detection when used in the context of DCOM/COM+)

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941455

These kind of "what's my environment" questions always have the same answer. Your host has no trouble figuring out if it is managed, just add a property to your interface to let it tell you. A trivial solution compared with the alternative. Which is impossible to implement reliably in COM, lots of ways to host a server.

Upvotes: 2

Related Questions