-
April 22nd, 2010, 11:03 AM
#1
new operator in DllMain of MFC Extension Dll
Hi,
Dll best practices document from Microsoft available at MSDN recommends avoiding use of memory management function from the dynamic C Run-Time (CRT) within DllMain. But DllMain function of MFC Extension DLL is dynamically allocating the memory for CDynLinkLibrary in the code snippet available at MSDN "http://msdn.microsoft.com/en-us/library/1btd5ea3%28v=VS.80%29.aspx".
Is it a violation of Dll Best Practices or ok to use in MFC extension DLL?
thanks
-
April 22nd, 2010, 12:20 PM
#2
Re: new operator in DllMain of MFC Extension Dll
It does seem contradictory. But what you have to realize is that DllMain isn't the true entry point...
http://msdn.microsoft.com/en-us/library/f9t8842e.aspx
So when the linker is resolving symbols for your DLL, it will find "_DllMainCRTStartup" in the LIB for your CRT. Allowing the CRT to do what it needs to do before calling your DllMain.
So I suppose it's safe to assume that "new" doesn't do anything "bad" while being called from DllMain. On the other hand, there's nothing stopping you from not doing that either - just export DllStartup/DllShutdown symbols and require users to call them before/after using your dll.
gg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|