Where is DLLMain in a C# DLL?
-
Thursday, September 06, 2007 9:07 PM
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
All Replies
-
Thursday, September 06, 2007 9:28 PMModerator
No DllMain(), it's evil in many respects due to the loader lock. Check this thread for reference. -
Friday, September 07, 2007 4:06 AM
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

