Question

I'm working my way through learning writing a COM control. I've got an example project, and it uses the lines

_pAtlModule->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!

Was it helpful?

Solution

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!).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top