How to execute code when a DLL loads?

  • Thread starter Thread starter andrew.miadowicz
  • Start date Start date
A

andrew.miadowicz

I need to run some code when my dll is loaded (specifically when the
Visual Studio designer loads my dll). I know about static constructors
and I've tried to place the code in there, but the problem is these
don't actually execute until the types they're in get instantiated.
What I actually try to do is to register those types to be used in the
Visual Studio designer for some third party controls. So I am running
into a chicke and egg problem: I need to register my types so that they
can be used in the designer, but my registration code doesn't run until
somebody uses an instance of one of the types.

It would be nice to have some form of an OnLoad method that would
execute when a DLL first loaded, before any particular types got
instantiated. Is there such a thing?

I've seen this post:
http://groups.google.com/group/micr...885d63a7?q=OnLoad+dll&rnum=1#dcf5a967885d63a7

It seems to suggest such a thing exists, but doesn't explain how to get
a hold of it.

Please help.

Thanks,

Andrew
 
Andrew,
What I actually try to do is to register those types to be used in the
Visual Studio designer for some third party controls.

Can't you handle such registration in a setup package?

It seems to suggest such a thing exists, but doesn't explain how to get
a hold of it.

It does (in .NET 2.0) but not all languages let you define such a
method.


Mattias
 
Mattias,

The "registration" I'm referring to is really just the process of
letting this particular third party control designer know that my
editors are available for it to use. This registration is not
persisted anywhere outside of the Visual Studio designer memory. In
fact, if I'm not mistaken (I only had so much time to analyze their
source code) the editors that ship with their package only get
registered when one of their controls (that can host such editors) is
instantiated on the Visual Studio designer.

Besides, in my particular case I'm working on a project in which I both
create and use my custom editors, and consequently no installation
takes place, as everything is a part of one big solution.

As far as the "OnLoad" method I am curious to know if C# 2.0 allows me
to define it somehow. Are there any other workarounds?

Thanks,

Andrew
 
Back
Top