aokhovat

I am writing a simple class library with C# that exports a class. The DLL needs to do some initialization once a process loads it. In the good old days of VC++ 6.0 (and Win32), you could rely on DLLMain to do that. However, I can not find a counterpart to DLLMain in the .Net framework. Any comments would be appreciated.

Thanks



Re: .NET Base Class Library Where is DLLMain in a C# DLL?

nobugz

No DllMain(), it's evil in many respects due to the loader lock. Check this thread for reference.





Re: .NET Base Class Library Where is DLLMain in a C# DLL?

svoeller99

To substitute for DLLMain, you could employ a static constructor on the class you're exporting to fire your initialization code. It will fire in a thread-safe manner the first time the type is accessed, prior to execution of any other code in that type. Check here for more info: http://msdn2.microsoft.com/en-us/library/Aa645612(VS.71).aspx