DLLMain in assemblies?

  • Thread starter Thread starter Jozsef Bekes
  • Start date Start date
J

Jozsef Bekes

Hi All,

is there a mechanism just like DllMain in VC6, a function that gets called
whenever an assembly gets loaded?

Thank you for all answers.

Jozsi
 
It's not something that you want to us e in managed code.

MSDN says:
DllMain
The DllMain function is a user defined entry point for a DLL. Unless the
user specifies otherwise, DllMain is invoked every time a process or thread
attaches to or detaches from the containing DLL. Since this invocation can
occur while the loader lock is held, no user-supplied DllMain function
should be compiled to MSIL. Furthermore, no function in the call tree rooted
at DllMain can be compiled to MSIL. To resolve issues here, the code block
that defines DllMain should be modified with #pragma unmanaged, or the
object file containing DllMain should be compiled without the CLR switch.
The same should be done for every function that DllMain calls.

see http://msdn2.microsoft.com/library/ms173266(en-us,vs.80).aspx
 
Jozsef Bekes said:
Hi All,

is there a mechanism just like DllMain in VC6, a function that gets called
whenever an assembly gets loaded?

Thank you for all answers.

Jozsi

When you create a new instance of ANY class, the Public Sub New() gets
called. You can override this if needed. You can also implement IDisposable
to call the Dispose() method of your class to tear things down. As far as
one all inclusive method for the entire DLL, there is none. The reason
being, I would suspect, is because DllMain get's called mainly in a Dll
exposing API methods, in which the whole Dll is acted apon, whereas in .NET,
the entire Assambly is loaded, but only the specific class/object you call is
initiated.
o, in closing, put a Sub New() in all your classes, and maybe look into
IDisposable to make your Dll really able to take care of it's resources.

HTH,
Jody
 
Hi Jody,

thank you for your answer. For solving the problem I chose to use singletons
instead of globals. If anyone has any better idea, please let me know.

Jozsi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top