COM - what does _pAtlModule->Lock() lock exactly?
I'm working my way through learning writing a COM control. I've got an example project, and it uses the lines
_pA开发者_开发百科tlModule->Lock()
_pAtlModule->Unlock()
in the OnCreate() handler and the OnDestroy() handler for the COM control respectively.
I realise that the _pAtlModule is an instance of the CAtlModule - the "application" object (for want of a better description ).
But to my question. What exactly does _pAtlModule->Lock() lock? I know it's a critical section, but what is it protecting?
Must I Lock and Unlock the _pAtlModule object when writing my COM controls?
thanks!
On the outsude, it doesn't actually appear to do anything substantial!
MSDN says "It increases the Lock count and returns the updated value; This may be useful for debugging and tracing".
http://msdn.microsoft.com/en-US/library/9syc2105%28v=VS.80%29.aspx
I think this is misleading however, the behavior is intended to stop the module from being unloaded. I theorize it's some atomic value that's used as a lock anchor (for want of a better term!).
See this answer to a similar question This function is for managing so-called "lock count" of the in-proc COM server DLL. Together with DllCanUloadNow()
the lock count prevents the DLL from being unloaded until its code and data is of no use anymore.
精彩评论