Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This class holds a critical section for the scope of a block or function.

The constructor locks the critical section and the destructor unlocks it.

The object passed to the CAutoLockconstructor must be derived from the CCritSecclass.

By declaring a CAutoLockobject as a local variable in a function, a critical section can be locked without the danger of forgetting to unlock it in some of the code paths: the destructor ensures that upon exit from the function (or the scope of the declaration), the critical section will be unlocked.

Member functions in this class are not designed for overriding.

Copy Code
/* Typical usage ensuring object is always unlocked correctly */
HRESULT MyFunc(IMediaSample *pSample)
{
   CAutoLock cObjectLock(m_pMyLock);
   /* Ignore samples passed when inactive */
   if (!m_bActive) {
	return NOERROR;
   }
   /* Add the sample to the pending queue */
   HRESULT hr = m_PendingList.AddTail(pSample);
   if (FAILED(hr)) {
	pSample->Release();
	return hr;
   }
   return NOERROR;
}

Protected Data Members

Member Description

M_pLock

Critical section for this lock.

Member Functions

Member function Description

CAutoLock

Takes a pointer to a critical section object and locks it.

Requirements

Windows Embedded CE Windows CE 2.12 and later
Windows Mobile Windows Mobile Version 5.0 and later
Note Microsoft DirectShow applications and DirectShow filters have different include file and Library requirements
For more information, see Setting Up the Build Environment