HRESULT VerifyCurrentMessage(STCANDATA& sCanData, CTSExecutionCAN* pTSXCan)
{
    AfxTrace("In VERIFY - Before Enter\n");
    EnterCriticalSection(&(pTSXCan->m_omCritSecTS));
    AfxTrace("In VERIFY - After Enter\n");
    
    if(pTSXCan->m_bTimeOver == TRUE || pTSXCan->m_pCurrentVerify == NULL)
    {
        LeaveCriticalSection(&(pTSXCan->m_omCritSecTS));
        return S_FALSE;
    }
    UINT unCount;
    pTSXCan->m_pCurrentVerify->GetSubEntryCount(unCount);
    if(pTSXCan->m_MsgVerifiedList.GetCount() < (INT)unCount)
    {
        CVerify_MessageData ouMsgData;
       
        
        if(pTSXCan->m_pCurrentVerify->GetMessageFromId(sCanData.m_uDataInfo.m_sCANMsg.m_unMsgID, &ouMsgData) == S_OK)
	    {
            if (pTSXCan->m_MsgVerifiedList.Find(sCanData.m_uDataInfo.m_sCANMsg.m_unMsgID) == NULL)
            {
                UCHAR pucData[8] = {0};
                memcpy(pucData, &sCanData.m_uDataInfo.m_sCANMsg.m_ucData, sCanData.m_uDataInfo.m_sCANMsg.m_ucDataLen);
            
                CSignalInfoArray ouSignalInfo;
                //Interprete The Messages
                sMESSAGE sMsg; 
                SMSGENTRY *sMsgEntry = new SMSGENTRY;
                pTSXCan->m_pCurrentVerify->m_ouDataBaseManager.nGetMessageInfo(ouMsgData.m_omMessageName, sMsg);
                sMsgEntry->m_psMsg = &sMsg;
                sMsgEntry->m_psNext = NULL;
                pTSXCan->m_ouMsgInterpret.vSetMessageList(sMsgEntry);
                pTSXCan->m_ouMsgInterpret.bInterpretMsgs(ouMsgData.m_dwMessageID, pucData, ouSignalInfo);
                CMessageResult ouMsgResult;
                if( pTSXCan->bVerifyCanMessage(ouMsgData, ouSignalInfo, ouMsgResult) == TRUE)
                {   
                    //pTSXCan->m_nVerifyCount++;
                    
                    if(pTSXCan->m_ouVerifyResult != NULL && pTSXCan->m_bTimeOver == FALSE)
                    {
                        //pTSXCan->TSX_DisplayMessage(ouMsgData.m_omMessageName);
                        //pTSXCan->TSX_DisplayResult(CString("SUCCESS"));
                        pTSXCan->m_ouVerifyResult->m_MessageResultList.AddTail(ouMsgResult);
                    }
                    pTSXCan->m_MsgVerifiedList.AddTail((UINT&)ouMsgData.m_dwMessageID);
                }
            }
        }
    }
    if(pTSXCan->m_MsgVerifiedList.GetCount() == (INT)unCount)
    {
        //pTSXCan->m_nVerifyCount = 0;
        pTSXCan->m_pCurrentVerify = NULL;
        pTSXCan->m_ouVerifyEvent.SetEvent();
        //pTSXCan->m_ouReadThread.m_unActionCode = INVOKE_FUNC;
    }
    LeaveCriticalSection(&(pTSXCan->m_omCritSecTS));
    return S_OK;
}
int ConvertFile(LPCTSTR lpFileNameIn, LPCTSTR lpFileNameOut, int nConvertWay)
{
	CStdioFile fileIn;
	if(!fileIn.Open(lpFileNameIn, CFile::modeRead))
	{
		AfxTrace(_T("Failed to Open file %s\n"), lpFileNameIn);
		return 0;
	}

	CStdioFile fileOut;
	if(!fileOut.Open(lpFileNameOut, CFile::modeReadWrite | CFile::modeCreate))
	{
		fileIn.Close();
		AfxTrace(_T("Failed to Open file %s\n"), lpFileNameOut);
		return 0;
	}
	
	int nResult = 0;

	CString bufRead;	
	while(fileIn.ReadString(bufRead))
	{	
		CString bufWrite;
 		Convert(bufRead, bufWrite, nConvertWay);
		bufWrite += "\n";
		fileOut.WriteString(bufWrite);
	}
	fileIn.Close();
	fileOut.Close();
	return nResult;
}
int MultiByteToMultByte(LPCSTR lpMultiByteStrSrc, int cbMultiByteSrc, UINT nCPSrc, 
						LPSTR lpMultiByteStrDst, int cbMultiByteDst, UINT nCPDst, DWORD dwFlags)
{
	LPWSTR lpWideCharStr = new WCHAR[cbMultiByteDst];

	int nResult = 0;
	do 
	{
		nResult = ::MultiByteToWideChar(nCPSrc, dwFlags, lpMultiByteStrSrc, cbMultiByteSrc, lpWideCharStr, cbMultiByteDst);
		if(nResult == 0)
		{
			AfxTrace("MultiByteToWideChar Failed. Error code = %d\n", GetLastError());
			break;
		}

		BOOL bUsedDefaultChar = TRUE;
		nResult = ::WideCharToMultiByte(nCPDst, 0, lpWideCharStr, nResult, lpMultiByteStrDst, cbMultiByteDst, "?", &bUsedDefaultChar);
		if(nResult == 0)
		{
			AfxTrace("WideCharToMultiByte Failed. Error code = %d\n", GetLastError());
			break;
		}
		if(bUsedDefaultChar)
		{
			AfxTrace("Used default char when converting [%s]\n", lpMultiByteStrSrc);
			break;
		}

	} while (FALSE);

	//Clean up
	delete lpWideCharStr;
	return nResult;
}
void CThreadMonitor::StopMonitor(BOOL bWait, DWORD dwTimeOut)
{
	::SetEvent(m_hQuitEvent);

	if(m_hMonitor)
	{
		//Should we wait?
		if(bWait)
		{
			DWORD dwResult = ::WaitForSingleObject(m_hMonitor, dwTimeOut);
			
			//abnormal case, here try to terminate thread
			if(dwResult == WAIT_ABANDONED || dwResult == WAIT_TIMEOUT)
			{
				BOOL bResult = TerminateThread(m_hMonitor, RC_EXIT_TERMINATED);
				AfxTrace("TerminateThread result = %d, dwResult = %d\n", bResult, dwResult);
			}
			//There's nothing to do with WAIT_OBJECT_0 and WAIT_FAILED
		}

		//Finally close the monitor thread
		::CloseHandle(m_hMonitor);
		m_hMonitor = NULL;
	}
}
bool MiscUtils::Val2Str(const _variant_t& var, std::string& str)
{
	bool bDone = true;
	switch(var.vt)   
	{
	case VT_BSTR:
	case VT_LPSTR:
	case VT_LPWSTR:
		try
		{
			str.assign((LPCSTR)(_bstr_t)var);
		}
		catch (...)
		{
			bDone = false;
			AfxTrace(_T("Val2Str failed\n"));
		}
		break;
	case VT_EMPTY:
		str.erase();
		break;
	default:
		bDone = false;
		break;
	}
	return bDone;
}
DWORD CThreadMonitor::DoMonitor()
{
	DWORD dwResult = 0, dwWaitResult = 0;

	int nCount = 0;
	RefreshWaitObjects(&nCount);
	ASSERT(nCount > 0);

	while(TRUE)
	{
		AfxTrace("WaitForMultipleObjects count = %d\n", nCount);
		if(nCount == 0)
		{
			ASSERT(m_bMonitoring == FALSE);

			dwResult = RC_EXIT_ALL_MONITEE_EXITED;
			AfxTrace("Stopped monitorring. Result code=%d\n", dwResult);

			return dwResult;
		}

		dwWaitResult = WaitForMultipleObjects(nCount, m_hWaitObjects, FALSE, INFINITE);

		//Objects signaled
		if(dwWaitResult >= WAIT_OBJECT_0 && dwWaitResult < (WAIT_OBJECT_0 + nCount))
		{
			dwResult = ProcessSignaled(dwWaitResult, nCount);
			if(dwResult != 0)
			{
				AfxTrace("Stopped monitorring. Result code=%d\n", dwResult);
				return dwResult;
			}

			RefreshWaitObjects(&nCount);
		}
		else
		{
			dwResult = ProcessAbnormal(nCount, dwWaitResult);
			if(dwResult != 0)
			{
				return dwResult;
			}
		}
	}

	return 0;
}
Beispiel #7
0
void CSListCtrl::OnHeaderClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
	
	AfxTrace("[OnHeaderClick]: iItem=%d, iButton=%d\n", phdn->iItem, phdn->iButton);
	
	*pResult = 1;
}
Beispiel #8
0
void CPreviewCtrl::OnTimer(UINT nIDEvent)
{
	ASSERT(m_nFrame >= 0);
	m_nFrame++;
	AfxTrace("OnTimer: %d\n", m_nFrame);

	InvalidateRect(NULL, TRUE);
}
Beispiel #9
0
void AfxTraceV(IDispatch *pDisp, const char* fmt, ...)
{
	char line[MAX_LINE_SIZE];
	va_list arg;
	va_start(arg, fmt);
	vsprintf(line, fmt, arg);
	va_end(arg);
	AfxTrace(pDisp, line);
}
Beispiel #10
0
void CPreviewCtrl::StartPreview()
{
	if(m_nTimer != 0)
	{
		AfxTrace("StartPreview: m_nTimer=%d\n", m_nTimer);
		return;
	}
	m_nTimer = SetTimer(1, 40, 0);
}
int CTestAction::DoAction()
{
	CString szLog;
	szLog.Format("The handle is closed now. handle=%08X, name=%s", m_hHandle, m_szName);
	
	AfxTrace("%s\n", szLog);

	if(m_hHandle)
	{
		if(!::CloseHandle(m_hHandle))
		{
			AfxTrace("Failed to Close Handle. %d\n", GetLastError());
		}
	}

	Sleep(2000);
	

	return DELETE_BY_EXTERNAL;
}
Beispiel #12
0
BOOL CToolBarCtrlEx::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
	if(!CToolBarCtrl::Create(dwStyle, rect, pParentWnd, nID))
	{
		return FALSE;
	}
	ASSERT(pParentWnd != NULL && pParentWnd->m_hWnd != NULL);
	AfxTrace("Add Msg Receiver: %x\n", pParentWnd->m_hWnd);
	m_msgReceivers.Add(pParentWnd->m_hWnd);
	return TRUE;
}
Beispiel #13
0
int GBKToGB2312(LPCSTR lpMultiByteStrSrc, int cbMultiByteSrc, LPSTR lpMultiByteStrDst, int cbMultiByteDst)
{
	DWORD dwLCID = MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_BIG5);
	int nResult = 0;
	nResult = ::LCMapString(dwLCID, LCMAP_SIMPLIFIED_CHINESE, lpMultiByteStrSrc, cbMultiByteSrc, lpMultiByteStrDst, cbMultiByteDst);
	if(nResult == 0)
	{
		AfxTrace("LCMapString Failed. Error code = %d\n", GetLastError());
	}
	return nResult;
}
Beispiel #14
0
BOOL CListCtrlEx::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
    if(pMsg->message == WM_KEYDOWN)
    {
        if(GetKeyState(VK_TAB)<0)
        {
            AfxTrace(_T("I got the message\n"));
        }
    }
    return CFFListCtrl::PreTranslateMessage(pMsg);
}
Beispiel #15
0
void CPreviewCtrl::StopPreview()
{
	if(m_nTimer == 0)
	{
		AfxTrace("StopPreview: m_nTimer=0\n");
		return;
	}
	KillTimer(m_nTimer);

	m_nTimer = 0;
	m_nFrame = 0;
}
Beispiel #16
0
/*
bool TestStream::SubmitSamples(LPBYTE pData, UINT nLength)
{
	if ((pData == NULL) || (nLength == 0))
		return false;

	CSingleLock lock(&m_cs, TRUE);

	if ((m_memBuffer.GetMemoryLength() - m_nBufferLength) < nLength)
	{
		AfxTrace(_T("Dropping samples\n"));
		return true;
	}

	UINT nStart = (m_nBufferStart + m_nBufferLength) % m_memBuffer.GetMemoryLength();
	UINT n1 = min(nStart + nLength, m_memBuffer.GetMemoryLength()) - nStart;

	memcpy(m_memBuffer.GetMemoryPointer() + nStart, pData, n1);

	if (n1 != nLength)
	{
		memcpy((m_memBuffer.GetMemoryPointer() + 0), (pData + n1), (nLength - n1));
	}

	m_nBufferLength += nLength;

	ASSERT(m_nBufferLength <= m_memBuffer.GetMemoryLength());

	if (m_nBufferLength >= (GetSamplesPerPacket() * 2 * sizeof(short)))
		SetEvent(m_hDataEvent);

	return true;
}
*/
int TestStream::ReadPacket()
{
	UINT nSize = GetSamplesPerPacket() * 2 * sizeof(short);

	CSingleLock lock(&m_cs, TRUE);
retry_read:
	if (m_bRunning == false)
		return 0;

	if (m_nBufferLength < nSize)
	{
		lock.Unlock();

		HANDLE hHandles[] = { m_hQuitEvent, m_hDataEvent };

		DWORD dw = WaitForMultipleObjects(sizeof(hHandles)/sizeof(hHandles[0]), hHandles, FALSE, INFINITE);
		if (dw == (WAIT_OBJECT_0 + 0))
		{
			return 0;
		}
		else if (dw == (WAIT_OBJECT_0 + 1))
		{
			lock.Lock();

			if (m_nBufferLength < nSize)
			{
				AfxTrace(_T("TestStream::ReadPacket received un-block event, but not yet enough data in buffer\n"));
				goto retry_read;
			}
		}
		else
		{
			ASSERT(FALSE);

			return 0;
		}
	}

/*	UINT n1 = min(m_nBufferStart + nSize, m_memBuffer.GetMemoryLength()) - m_nBufferStart;

	memcpy(m_mem.GetMemoryPointer(), (m_memBuffer.GetMemoryPointer() + m_nBufferStart), n1);

	if (n1 != nSize)
	{
		memcpy((m_mem.GetMemoryPointer() + n1), (m_memBuffer.GetMemoryPointer() + 0), (nSize - n1));
	}

	ASSERT(m_nBufferLength >= nSize);
	m_nBufferLength -= nSize;
	m_nBufferStart = (m_nBufferStart + nSize) % m_memBuffer.GetMemoryLength();
*/
	return GetSamplesPerPacket();
}
Beispiel #17
0
void CBrowseEditItem::OnKillFocus(CWnd* pNewWnd)
{
    CEdit::OnKillFocus(pNewWnd);

    // TODO: Add your message handler code here
    if( pNewWnd // NULL condition
            && pNewWnd != GetParent()->GetParent() //For Dialog Close using X Button
            && pNewWnd->GetDlgCtrlID() != IDCANCEL ) // For Cancel condition
    {
        AfxTrace("In if Condition\n");
        CString str;
        GetWindowText(str);
        // Send Notification to parent of ListView ctrl
        LV_DISPINFO lvDispInfo;
        lvDispInfo.hdr.hwndFrom = GetParent()->m_hWnd;
        lvDispInfo.hdr.idFrom = GetDlgCtrlID();
        lvDispInfo.hdr.code = LVN_ENDLABELEDIT;
        lvDispInfo.item.mask = LVIF_TEXT;
        lvDispInfo.item.iItem = m_nItem;
        lvDispInfo.item.iSubItem = m_nSubItem;
        // Restore the old text on press of ESCAPE key
        lvDispInfo.item.pszText =
            m_bVK_ESCAPE ? LPTSTR((LPCTSTR)m_sContent) : LPTSTR((LPCTSTR)str);
        lvDispInfo.item.cchTextMax = str.GetLength();
        // Send the notification message to the parent
        GetParent()->GetParent()->SendMessage( WM_NOTIFY,
                                               GetParent()->GetDlgCtrlID(),
                                               (LPARAM)&lvDispInfo);
    }

    //HWND hNewWnd = 0;
    if(pNewWnd != NULL)
    {
        if(m_pomButton->GetSafeHwnd() == pNewWnd->GetSafeHwnd())
        {
            return;
        }
    }

    if((((CButtonItem*)m_pomButton)->m_bButtonclicked == FALSE) && (m_bKillFocus ==  TRUE))
    {
        ((CButtonItem*)m_pomButton)->m_bIsEditValid = FALSE;

        if(m_bIsButtonValid == TRUE)
        {
            ((CButtonItem*)m_pomButton)->m_bKillFocus = TRUE;
            m_pomButton->SendMessage(WM_KILLFOCUS, 0, 0);
        }

        DestroyWindow();
    }
}
Beispiel #18
0
BOOL CSListCtrl::IsPtInSubItemCheckBox(int nItem, int nSubItem, POINT pt)
{
	BOOL bResult = FALSE;
	
	CRect checkboxRect;
	if(CalcCheckBoxRect(nItem, nSubItem, checkboxRect))
	{
		bResult = checkboxRect.PtInRect(pt);
	}

	AfxTrace("IsPtInSubItemCheckBox: %d\n", bResult);
	return bResult;
}
Beispiel #19
0
void CMemLeakDetect::removeMemoryTrace(void* addr, void* realdataptr)
{
	AllocBlockInfo ainfo;
	//
	if (m_AllocatedMemoryList.Lookup(addr,(AllocBlockInfo &) ainfo))
	{
		m_AllocatedMemoryList.RemoveKey(addr);
	}
	else
	{
	   //freeing unallocated memory
		AfxTrace(_T("ERROR!CMemLeakDetect::removeMemoryTrace() didnt find Address(0x%08X) to free\n"), addr);
	}
};
Beispiel #20
0
void CToolBarCtrlEx::Refresh()
{
	// Causes a toolbar to be resized.
	AutoSize();

	//Send message to all the receivers.
	int nMsgReceiverCount = m_msgReceivers.GetSize();
	LRESULT lr = 0;
	for(int i = 0; i < nMsgReceiverCount; i++)
	{
		AfxTrace("Send Msg to: %x\n", m_msgReceivers.GetAt(i));
		lr = ::SendMessage(m_msgReceivers.GetAt(i), UM_TOOLBARCTRLX_REFRESH, 0, 0);
	}
}
Beispiel #21
0
void CYTGetApp::InitLog4cplus()
{

#ifdef ENABLE_LOG4CPLUS	
	const char* pLogFileSuffixName = "LOG_FILE_SUFFIX";
	CString szLogFileSuffix = getenv(pLogFileSuffixName);
	
	const char* pAppWorkDirName = "APP_WORK_DIR";
	CString szAppWorkDir = getenv(pAppWorkDirName);
	
	//Set the env to the current time str
	CString sTime = CTime::GetCurrentTime().Format("_%Y_%m_%d_%H_%M_%S");
	
	CString szValue;
	szValue.Format("%s=%s", pLogFileSuffixName, sTime);
	_putenv(szValue);
	
	szValue.Format("%s=%s", pAppWorkDirName, m_szWorkDir);
	_putenv(szValue);
	
	CString szConfigFile;
	szConfigFile.Format("%s\\log4cplus.properties", m_szWorkDir);
	try
	{
		//This will take effect in the configure process
		log4cplus::PropertyConfigurator::doConfigure((LPCTSTR)szConfigFile);

		{
			CString szLog;
			szLog.Format("Config File=%s", szConfigFile);
			LOG4CPLUS_INFO_STR(ROOT_LOGGER, (LPCTSTR)szLog)
		}
	}
	catch(...) 
	{
		CString sLogInfo;
		sLogInfo.Format("Exception occured when configure log4cplus, config file = %s", szConfigFile);
		AfxTrace("%s\n", sLogInfo);
		LOG4CPLUS_FATAL(ROOT_LOGGER, (LPCTSTR)sLogInfo)
	}
	
	//After configuration, restore the environment variable.
	szValue.Format("%s=%s", pLogFileSuffixName, szLogFileSuffix);
	_putenv(szValue);
	
	szValue.Format("%s=%s", pAppWorkDirName, szAppWorkDir);
	_putenv(szValue);
#endif
}
Beispiel #22
0
void CPreviewCtrl::OnTimer(UINT nIDEvent) 
{
	if(m_nFrame < 0)
	{
		m_nFrame = 0;
	}
	else
	{
		m_nFrame++;
	}
	if(m_nFrame > m_nTotalFrames)
	{
		m_nFrame = 0;
		StopPreview();
	}
	AfxTrace("OnTimer: m_nFrame=%d\n", m_nFrame);

	InvalidateRect(NULL, TRUE);
	
	CStatic::OnTimer(nIDEvent);
}
Beispiel #23
0
BOOL CSListCtrl::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	*pResult = 0;

	AfxTrace("[OnColumnClick]: iItem=%d\n", pNMListView->iSubItem);
	
	int nSubItem = pNMListView->iSubItem;

	//1. Check if clicked a check box in header
	if(!m_HeaderCtrl.IsClickedCheckBox(nSubItem))
	{
		//CTRL key is pressed
		m_pSortable->SortColumn(nSubItem, ::GetKeyState( VK_CONTROL ) < 0);
		return FALSE;
	}
	
	//2. Clicked check box in header
	int nCheckedState = GetHeaderCheckedState(nSubItem);
	
	// CHECK_LIST_CTRL_NO_IMAGE = no checkbox
	if (nCheckedState != SHC_NONE_CHECK_BOX)
	{
		nCheckedState = SwitchCheckedState(nCheckedState);

		SetHeaderCheckedState(nSubItem, nCheckedState);
		m_HeaderCtrl.UpdateWindow();
		
		for (int nItem = 0; nItem < GetItemCount(); nItem++)
		{
			if (GetItemCheckedState(nItem, nSubItem) != SHC_NONE_CHECK_BOX)
			{
				SetItemCheckedState(nItem, nSubItem, nCheckedState);
			}
		}
		UpdateWindow();
	}
	return FALSE;
}
Beispiel #24
0
BOOL CPreviewCtrl::SaveToFile(BITMAPFILEHEADER* pBFH, BITMAPINFOHEADER* pBIH, LPVOID lpDibData, LPCTSTR lpszFileName)
{
	HANDLE hFile = CreateFile(lpszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hFile == INVALID_HANDLE_VALUE)
    {
        return FALSE;
    }
	
	BOOL bOK = FALSE;
	DWORD dwWrite = 0;
	do 
	{
		if(!WriteFile(hFile, pBFH, sizeof(BITMAPFILEHEADER), &dwWrite, NULL))
		{
			break;
		}
		
		if(!WriteFile(hFile, pBIH, sizeof(BITMAPINFOHEADER), &dwWrite, NULL))
		{
			break;
		}
		if(!WriteFile(hFile, lpDibData, pBIH->biSizeImage, &dwWrite, NULL))
		{
			break;
		}
		bOK = TRUE;
	} while (FALSE);
	
	CloseHandle(hFile);
	
	if(!bOK)
	{
		DWORD dwErrorCode = GetLastError();
		AfxTrace("%08X\n", dwErrorCode);
	}
	
	return bOK;
}
DWORD CThreadMonitor::ProcessSignaled(DWORD dwRet, int nCount)
{
	ASSERT(dwRet >= WAIT_OBJECT_0 && dwRet < (WAIT_OBJECT_0 + nCount));

	int nSingaledCount = 0;
	int pSingaledIndex[MAX_WAIT_COUNT];
	
	int nFirstMonitee, nControlEventEnd;	

	GetSignaledObjects(dwRet, nCount, pSingaledIndex, &nSingaledCount);
	ASSERT(nSingaledCount > 0 && nSingaledCount <= nCount);
	//Debug Code
	CString szLog, szTemp;
	szLog.Format("[Signaled Objects]: count=%d, ", nSingaledCount);
	for(int i = 0; i < nSingaledCount; i++)
	{
		szTemp.Format("%d ", pSingaledIndex[i]);
		szLog += szTemp;
	}
	AfxTrace("%s\n", szLog);
	
	nFirstMonitee = FindFirstMonitee(pSingaledIndex, nSingaledCount);
	if(nFirstMonitee >= 0)
	{
		ProcessSignaledMonitees(pSingaledIndex, nSingaledCount, nFirstMonitee);
		nControlEventEnd = nFirstMonitee;
	}
	else
	{
		ASSERT(nSingaledCount <= MAX_CONTROL_EVENT_COUNT);
		nControlEventEnd = nSingaledCount;
	}
	
	DWORD dwResult = ProcessSignaledControlEvents(pSingaledIndex, nControlEventEnd);
	
	return dwResult;
}
Beispiel #26
0
void CMemLeakDetect::addMemoryTrace(void* addr,  size_t asize,  TCHAR *fname, DWORD lnum)
{
	AllocBlockInfo ainfo;
	//
	if (m_AllocatedMemoryList.Lookup(addr, ainfo))
	{
		// already allocated
		AfxTrace(_T("ERROR!CMemLeakDetect::addMemoryTrace() Address(0x%p) already allocated\n"), addr);
		return;
	}
	//
	ainfo.address		= addr;
	ainfo.lineNumber	= lnum;
	ainfo.size			= asize;
	ainfo.occurance		= memoccurance++;
	MLD_STACKWALKER(&ainfo.traceinfo[0]);
	//
	if (fname)
		_tcsncpy_s(&ainfo.fileName[0], MLD_MAX_NAME_LENGTH, fname, MLD_MAX_NAME_LENGTH);
	else
	  ainfo.fileName[0] = 0;
	//
	m_AllocatedMemoryList.SetAt(addr, ainfo);
};
Beispiel #27
0
void CMemLeakDetect::redoMemoryTrace(void* addr,  void* oldaddr, size_t asize,  TCHAR *fname, DWORD lnum)
{
	AllocBlockInfo ainfo;
	if (m_AllocatedMemoryList.Lookup(oldaddr,(AllocBlockInfo &) ainfo))
	{
		m_AllocatedMemoryList.RemoveKey(oldaddr);
	}
	else
	{
		AfxTrace(_T("ERROR!CMemLeakDetect::redoMemoryTrace() didnt find Address(0x%08X) to free\n"), oldaddr);
	}
	//
	ainfo.address		= addr;
	ainfo.lineNumber	= lnum;
	ainfo.size			= asize;
	ainfo.occurance		= memoccurance++;
	MLD_STACKWALKER(&ainfo.traceinfo[0]);
	//
	if (fname)
		_tcsncpy_s(&ainfo.fileName[0], MLD_MAX_NAME_LENGTH, fname, MLD_MAX_NAME_LENGTH);
	else
	  ainfo.fileName[0] = 0;
	m_AllocatedMemoryList.SetAt(addr, ainfo);
};
DWORD CThreadMonitor::ProcessAbnormal(int nCount, DWORD dwResult)
{	
	CString szErrorMsg;
	if(dwResult >= WAIT_ABANDONED_0 && dwResult < (WAIT_ABANDONED_0 + nCount))
	{
		szErrorMsg.Format("WAIT_ABANDONED, index=%d", dwResult - WAIT_ABANDONED_0);
	}
	else if(dwResult == WAIT_TIMEOUT)
	{
		szErrorMsg.Format("WAIT_TIMEOUT");
	}
	else if(dwResult == WAIT_FAILED)
	{
		szErrorMsg.Format("WAIT_FAILED, Last Error=%d", GetLastError());
	}
	else
	{
		szErrorMsg.Format("Unkown result (%d)", dwResult);
	}

	AfxTrace("WaitForMultipleObjects return abnormal. Details: %s\n", szErrorMsg);

	return 0;
}
Beispiel #29
0
static void AFXAPI TraceDDE(LPCTSTR lpszPrefix, const MSG* pMsg)
{
	ENSURE_ARG(pMsg != NULL);
	if (pMsg->message == WM_DDE_EXECUTE)
	{
		UINT_PTR nDummy;
		HGLOBAL hCommands;
		if (!UnpackDDElParam(WM_DDE_EXECUTE, pMsg->lParam,
			&nDummy, (UINT_PTR*)&hCommands))
		{
			TRACE(traceAppMsg, 0, "Warning: Unable to unpack WM_DDE_EXECUTE lParam %08lX.\n",
				pMsg->lParam);
			return;
		}
		ASSERT(hCommands != NULL);

		LPCTSTR lpszCommands = (LPCTSTR)::GlobalLock(hCommands);
		ENSURE_THROW(lpszCommands != NULL, ::AfxThrowMemoryException() );
		TRACE(traceAppMsg, 0, _T("%s: Execute '%s'.\n"), lpszPrefix, lpszCommands);
		::GlobalUnlock(hCommands);
	}
	else if (pMsg->message == WM_DDE_ADVISE)
	{
		UINT_PTR nItem;
		ATOM aItem;
		HGLOBAL hAdvise;
		if (!UnpackDDElParam(WM_DDE_ADVISE, pMsg->lParam,
			(UINT_PTR*)&hAdvise, &nItem))
		{
			TRACE(traceAppMsg, 0, "Warning: Unable to unpack WM_DDE_ADVISE lParam %08lX.\n",
				pMsg->lParam);
			return;
		}
		aItem = (ATOM)nItem;
		ASSERT(aItem != NULL);
		ASSERT(hAdvise != NULL);

		DDEADVISE* lpAdvise = (DDEADVISE*)::GlobalLock(hAdvise);
		ENSURE_THROW(lpAdvise != NULL, ::AfxThrowMemoryException() );
		TCHAR szItem[80];
		szItem[0] = '\0';

		if (aItem != 0)
			::GlobalGetAtomName(aItem, szItem, _countof(szItem));

		TCHAR szFormat[80];
		szFormat[0] = '\0';
		if (((UINT)0xC000 <= (UINT)lpAdvise->cfFormat) &&
				((UINT)lpAdvise->cfFormat <= (UINT)0xFFFF))
		{
			::GetClipboardFormatName(lpAdvise->cfFormat,
				szFormat, _countof(szFormat));

			// User defined clipboard formats have a range of 0xC000->0xFFFF
			// System clipboard formats have other ranges, but no printable
			// format names.
		}

		AfxTrace(
			_T("%s: Advise item='%s', Format='%s', Ack=%d, Defer Update= %d\n"),
			 lpszPrefix, szItem, szFormat, lpAdvise->fAckReq,
			lpAdvise->fDeferUpd);
		::GlobalUnlock(hAdvise);
	}
}
Beispiel #30
0
void MyTraceMsg(LPCTSTR lpszPrefix, const MSG* pMsg)
{
    ASSERT(lpszPrefix != NULL);
    ASSERT(pMsg != NULL);

    if (/*pMsg->message == WM_MOUSEMOVE || */
        //pMsg->message == WM_NCMOUSEMOVE ||
        //pMsg->message == WM_NCHITTEST ||
        pMsg->message == WM_SETCURSOR ||
        pMsg->message == WM_CTLCOLORBTN ||
        pMsg->message == WM_CTLCOLORDLG ||
        pMsg->message == WM_CTLCOLOREDIT ||
        pMsg->message == WM_CTLCOLORLISTBOX ||
        pMsg->message == WM_CTLCOLORMSGBOX ||
        pMsg->message == WM_CTLCOLORSCROLLBAR ||
        pMsg->message == WM_CTLCOLORSTATIC ||
        pMsg->message == WM_ENTERIDLE || pMsg->message == WM_CANCELMODE ||
        pMsg->message == 0x0118)    // WM_SYSTIMER (caret blink)
    {
        // don't report very frequently sent messages
        return;
    }

    LPCSTR lpszMsgName = NULL;
    char szBuf[80];

    // find message name
    if (pMsg->message >= 0xC000)
    {
        // Window message registered with 'RegisterWindowMessage'
        //  (actually a USER atom)
        if (::GetClipboardFormatNameA(pMsg->message, szBuf, ARRAY_SIZE(szBuf)))
            lpszMsgName = szBuf;
    }
    else if (pMsg->message >= WM_USER)
    {
        // User message
        wsprintfA(szBuf, "WM_USER+0x%04X", pMsg->message - WM_USER);
        lpszMsgName = szBuf;
    }
    else
    {
        // a system windows message
        const TRACE_MAP_MESSAGE* pMapMsg = allMessages;
        for (/*null*/; pMapMsg->lpszMsg != NULL; pMapMsg++)
        {
            if (pMapMsg->nMsg == pMsg->message)
            {
                lpszMsgName = pMapMsg->lpszMsg;
                break;
            }
        }
    }

    if (lpszMsgName != NULL)
    {
        if(pMsg->message==WM_WINDOWPOSCHANGING || pMsg->message==WM_WINDOWPOSCHANGED )
        {
            LPWINDOWPOS pPos = (LPWINDOWPOS)pMsg->lParam;

            AfxTrace(_T("%s: hwnd=0x%04X, msg = %hs (%ld,%ld)(%ld,%ld)-0x%08lX\n"),
                     lpszPrefix, HWndToUInt(pMsg->hwnd), lpszMsgName,
                     pPos->x,pPos->y,pPos->cx,pPos->cy,pPos->flags);
        }
        else if(pMsg->message==WM_STYLECHANGING || pMsg->message==WM_STYLECHANGED )
        {
            LPSTYLESTRUCT pStyle =(LPSTYLESTRUCT)pMsg->lParam;

            AfxTrace(_T("%s: hwnd=0x%04X, msg = %hs %s New: 0x%08x, Old: 0x%08x\n"),
                     lpszPrefix, HWndToUInt(pMsg->hwnd), lpszMsgName,(LPCTSTR)((GWL_EXSTYLE==pMsg->wParam)?_T("EXSTYLE"):_T("STYLE")),
                     pStyle->styleNew,pStyle->styleOld);
        }
        else
        {
            AfxTrace(_T("%s: hwnd=0x%04X, msg = %hs (0x%04X, 0x%08lX)\n"),
                     lpszPrefix, HWndToUInt(pMsg->hwnd), lpszMsgName,
                     pMsg->wParam, pMsg->lParam);
        }
    }
    else
    {
        AfxTrace(_T("%s: hwnd=0x%04X, msg = 0x%04X (0x%04X, 0x%08lX)\n"),
                 lpszPrefix, HWndToUInt(pMsg->hwnd), pMsg->message,
                 pMsg->wParam, pMsg->lParam);
    }

//  if (pMsg->message >= WM_DDE_FIRST && pMsg->message <= WM_DDE_LAST)
//    TraceDDE(lpszPrefix, pMsg);
}