【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“WZDDATA.CPP”一文,供大家参考学习
// WzdData.cpp : implementation of the CWzdData class
//
#include "stdafx.h"
#include "WzdData.h"
/////////////////////////////////////////////////////////////////////////////
// CWzdData
IMPLEMENT_SERIAL( CWzdData, CObject, 0 )
CWzdData::CWzdData()
{
m_nInt=0;
m_fFloat=0.0f;
m_dwWord=0;
}
BOOL CWzdData::GetData(int *pInt,float *pFloat,DWORD *pWord)
{
// we lock here too so that we'll never read half written data
CSingleLock slock(&m_mutex);
if (slock.Lock(1000)) // timeout in milliseconds, default= INFINITE
{
// get values--can also be lists and arrays
*pInt=m_nInt;
*pFloat=m_fFloat;
*pWord=m_dwWord;
return TRUE;
}
return FALSE; // timed out!
// unlocks on return or you can call slock.Unlock();
}
BOOL CWzdData::SetData(int nInt,float fFloat,DWORD dwWord)
{
CSingleLock slock(&m_mutex); //or with CMultiLock can specify several m_mutex's
// for waiting on several data items
if (slock.Lock(1000)) // timeout in milliseconds, default= INFINITE
{
// set values--can also be lists and arrays
m_nInt=nInt;
m_fFloat=fFloat;
m_dwWord=dwWord;
return TRUE;
}
return FALSE; // timed out!
// unlocks on return or you can call slock.Unlock();
}