Reference not mandatory

  • Thread starter Thread starter jodleren
  • Start date Start date
J

jodleren

Hi all

We have a library,compiled as a DLL, which uses an ActiveX from
Beckhoff.

The point is, that we have apps, which does not need this ActiveX
(hence the compoents which uses it). Is there a way to have a library,
which does not require other references, but looks for them/enables
options if present?

I my current situation I dont care much, as I do not need it at all.

WBR
Sonnich
 
We have a library,compiled as a DLL, which uses an ActiveX from
Beckhoff.

The point is, that we have apps, which does not need this ActiveX
(hence the compoents which uses it). Is there a way to have a library,
which does not require other references, but looks for them/enables
options if present?

I my current situation I dont care much, as I do not need it at all.

Off the top of my head I'd say you might be able to get away with this by
using Activator.CreateInstance() to instantiate the ActiveX control (via its
..NET wrapper). That way, you could test for the presence of the control on
the target system (by examining the registry) and simply never call that
method if the control is not present.

There may be other solutions; this was the only thing that popped into my
mind.
 
We have a library,compiled as a DLL, which uses an ActiveX from
Beckhoff.

The point is, that we have apps, which does not need this ActiveX
(hence the compoents which uses it). Is there a way to have a library,
which does not require other references, but looks for them/enables
options if present?

I my current situation I dont care much, as I do not need it at all.

Load it dynamically.

Activator.CreateInstance(Type.GetTypeFromProgID("Foo.Bar"))

should do it.

And it is very easy in C#/.NET 4.0 where you can use
the dynamic keyword.

In earlier versions you will need to use reflection. And
if that COM stuff is like COM stuff usually are, then that
would be a nightmare.

So my recommendation is:

if C#/.NET 4.0 then use dynamic and Activator.CreateInstance +
Type.GetTypeFromProgID to dynamically use the COM stuff otherwise
split your DLL in two DLL's - one that you always need and
one that is build against the COM stuff - and the load the
second .NET assembly dynamically with Assembly.Load + CreateInstance.

Arne
 
Back
Top