int InputBoxDlg::StrMatchMBS( const TCHAR *Ptn, const TCHAR *Str ){ //追加 2012.12.01 //const char *Ptn …ワイルドカード付き文字列 //const char *Str …検索対象 //戻り値 …1/0:真/偽 //_mbsinc()を_tcsinc()に _mbsnextc()を_tcsnextc()に、変更 2011.09.09 switch( *Ptn ) { case _T('\0'): return (_tcsnextc(Str)==_T('\0')); case _T('*'): return StrMatchMBS( _tcsinc(Ptn), Str ) || (_tcsnextc(Str)!=_T('\0')) && StrMatchMBS( Ptn, _tcsinc(Str) ); case _T('?'): return (_tcsnextc(Str)!=_T('\0')) && StrMatchMBS( _tcsinc(Ptn), _tcsinc(Str) ); default: return (_tcsnextc(Ptn)==_tcsnextc(Str)) && StrMatchMBS( _tcsinc(Ptn), _tcsinc(Str) ); } }
bool IsValidBlueprintName (LPCTSTR pszName) { if (*pszName == 0) return false; while (*pszName) { int c = _tcsnextc (pszName); pszName = _tcsinc (pszName); if (!_istalnum (c) && c != '_') return false; } return true; }
bool IsValidProfileName (LPCTSTR pszName) { bool fHasStar = false; if (*pszName == 0) return false; while (*pszName) { int c = _tcsnextc (pszName); pszName = _tcsinc (pszName); if (!_istalnum (c) && c != '_') { if (c == '*') { if (fHasStar) return false; fHasStar = true; } else return false; } } return true; }
int DecodeToolbarButtons (LPCTSTR pszText, TBBUTTON *pTBBtns, int nMaxButtons) { int c; // // Initialize to no buttons // int nButtons = 0; // // Loop while we have buttons // while (*pszText) { // // Skip whitespace // while (true) { c = _tcsnextc (pszText); if (!_istspace (c)) break; pszText = _tcsinc (pszText); } // // Break if end of string // if (c == 0) break; // // Convert the next block of digits // LPTSTR pszEnd; errno = 0; unsigned long ulCmd = _tcstoul (pszText, &pszEnd, 10); if (errno != 0 || pszText == pszEnd) return -1; pszText = pszEnd; // // psz whitespace // while (true) { c = _tcsnextc (pszText); if (!_istspace (c)) break; pszText = _tcsinc (pszText); } // // This MUST be a comma or 0 // if (c == ',') pszText = _tcsinc (pszText); else if (c == 0) ; else return -1; // // We have a value // if (ulCmd == 0) { if (nButtons >= nMaxButtons) break; pTBBtns [nButtons].iBitmap = 8; pTBBtns [nButtons].idCommand = 0; pTBBtns [nButtons].fsState = 0; pTBBtns [nButtons].fsStyle = TBSTYLE_SEP; pTBBtns [nButtons].dwData = 0; pTBBtns [nButtons].iString = 0; nButtons++; } else { int i; for (i = 0; i < g_nCommands; i++) { if (g_asCommands [i] .nCmd == (int) ulCmd) break; } if (i < g_nCommands) { if (nButtons >= nMaxButtons) break; pTBBtns [nButtons].iBitmap = g_asCommands [i] .iBitmap; pTBBtns [nButtons].idCommand = g_asCommands [i] .nCmd; pTBBtns [nButtons].fsState = TBSTATE_ENABLED; pTBBtns [nButtons].fsStyle = g_asCommands [i] .fsStyle; pTBBtns [nButtons].dwData = 0; pTBBtns [nButtons].iString = 0; nButtons++; } } } return nButtons; }
DWORD LogDataToDisk(TCHAR *szModuleFilePath, TCHAR* szData, BOOL bAlertData) { TCHAR szFullPathDirectory[MAX_PATH + 100] = {0}; TCHAR szFileName[MAX_PATH + 100] = {0}; TCHAR szLogPath[MAX_PATH + 100] = {0}; TCHAR szTempLogPath[MAX_PATH + 100] = {0}; TCHAR szFullLogPath[MAX_PATH + 100] = {0}; TCHAR szMutexName[MAX_PATH + 100] = {0}; TCHAR szLogFileMapName[MAX_PATH + 100] = {0}; TCHAR* lpTraverser = NULL; TCHAR* szFindChar = NULL; TCHAR* pszString = NULL; TCHAR* pszFinalError = NULL; TCHAR chString = NULL; HANDLE hFile = NULL; HANDLE hMutex = NULL; DWORD nResult = 0; DWORD dwNumOfBytesWritten = 0; long lRet = 0; int iCtr = 0; int iSubCtr = 0; int iLen = 0; BOOL bFirstCreate = FALSE; __try { __try { if((NULL == szData) || (NULL == szModuleFilePath)) { return 1; } iLen = _tcslen(szModuleFilePath); if(0 == iLen) { return 1; } _tcscat(szLogFileMapName,_T("FILE_MAP_")); _tcscat(szMutexName,_T("FILE_MUTEX_")); for(iCtr = 0; iCtr < iLen; ++iCtr) { pszString = _tcsninc(szModuleFilePath,iCtr); chString = _tcsnextc(pszString); if(_T('\\') == chString) { _tcscat(szLogFileMapName,_T("-")); _tcscat(szMutexName,_T("-")); } else { _tcsncat(szLogFileMapName,pszString,1); _tcsncat(szMutexName,pszString,1); } } //Create the Mutex and wait hMutex = CreateMutex(NULL,FALSE,szMutexName); if(NULL == hMutex) { return 1; } nResult = WaitForSingleObject(hMutex,(300 * 1000)); if(WAIT_OBJECT_0 != nResult) { ::ReleaseMutex(hMutex); CloseHandle(hMutex); hMutex = NULL; return 1; } _tcscpy(szFullLogPath,szModuleFilePath); //Remove the file name szFindChar = strrchr(szFullLogPath,'\\'); if(NULL != szFindChar) { _tcscpy(szFileName,szFindChar); *szFindChar = NULL; //++szFindChar; } _tcscpy(szFullPathDirectory,szFullLogPath); _tcscat(szFullPathDirectory,szFileName); if(0 == ::SetFileAttributes(szFullPathDirectory,FILE_ATTRIBUTE_NORMAL)) { CreateLogDirectory(szFullLogPath); bFirstCreate = TRUE; } //::SetFileAttributes(szFullPathDirectory,FILE_ATTRIBUTE_NORMAL); //Create or opens the existing log file hFile = CreateFile(szFullPathDirectory, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return 1; } if(TRUE == bFirstCreate) { if(FALSE == bAlertData) { ::WriteFile(hFile, "DateTime\tApplication\tApp_Status\tMonitor\tCounter\tCounterStatus\r\n", lstrlen("DateTime\tApplication\tApp_Status\tMonitor\tCounter\tCounterStatus\r\n"), &dwNumOfBytesWritten, NULL); dwNumOfBytesWritten = 0; } } SetFilePointer(hFile, 0, NULL, FILE_END); ::WriteFile(hFile,szData,lstrlen(szData),&dwNumOfBytesWritten,NULL); CloseHandle(hFile); hFile = NULL; ::ReleaseMutex(hMutex); CloseHandle(hMutex); hMutex = NULL; return 0; } __except(EXCEPTION_EXECUTE_HANDLER) { //Its better to flush all the buffers //FlushFileBuffers(hFile); //Close the file handle if(NULL != hFile) { CloseHandle(hFile); hFile = NULL; } if(NULL != hMutex) { ::ReleaseMutex(hMutex); CloseHandle(hMutex); hMutex = NULL; } return 1; } } __finally { //Its better to flush all the buffers //FlushFileBuffers(hFile); //Close the file handle if(NULL != hFile) { CloseHandle(hFile); hFile = NULL; } if(NULL != hMutex) { ::ReleaseMutex(hMutex); CloseHandle(hMutex); hMutex = NULL; } } return 0; }