std::string TcharToStdString(LPWSTR inChar ) { CT2CA pszConvertedAnsiString(inChar); std::string szResult(pszConvertedAnsiString); return szResult; }
void TextSearcher::Find( const char * szText ) { if( regex_match( szText, m_expr ) ) { string szResult( szText ); m_FindBuffer.push_back( szResult ); } }
// 获取文件信息中的版本信息 CString GetFileVersion(const CString& strFilePath) { CString szResult(_T("0.0.0.0")); if (strFilePath.GetLength() <= 0 || !::PathFileExists(strFilePath)) { return szResult; } DWORD dwTemp; DWORD dwSize = ::GetFileVersionInfoSize(strFilePath, &dwTemp); if (dwSize == 0) { return szResult; } BYTE *pData = new BYTE[dwSize+1]; if (pData == NULL) { return szResult; } if (!::GetFileVersionInfo(strFilePath, 0, dwSize, pData)) { delete[] pData; return szResult; } UINT uLen; VS_FIXEDFILEINFO *pVerInfo = NULL; if (!::VerQueryValue(pData, TEXT("\\"), (void **)&pVerInfo, &uLen)) { delete[] pData; return szResult; } DWORD verMS = pVerInfo->dwFileVersionMS; DWORD verLS = pVerInfo->dwFileVersionLS; DWORD major = HIWORD(verMS); DWORD minor = LOWORD(verMS); DWORD build = HIWORD(verLS); DWORD revision = LOWORD(verLS); delete[] pData; szResult.Format(TEXT("%d.%d.%d.%d"), major, minor, build, revision); return szResult; }
CString Recognize(CString szUrl) { CString szResult(""); if (hasInit == FALSE || chkFilePath.IsEmpty()) { CString szFileName; DWORD nProcID = ::GetCurrentProcessId(); GetProcessNameByProcessID(nProcID, szFileName); int index = szFileName.ReverseFind('\\'); chkFilePath = szFileName.Left(index) + "\\chkcode.txt"; hasInit = TRUE; } CStdioFile file; if (szLastUrl != szUrl) { if (file.Open(chkFilePath, CFile::modeCreate | CFile::modeReadWrite)) { file.WriteString(szUrl); szLastUrl = szUrl; file.Close(); } } CString szLine(""); if (file.Open(chkFilePath, CFile::modeRead)) { file.ReadString(szLine); if (szLine.GetLength() > szUrl.GetLength() + 1) { szResult = szLine.Mid(szUrl.GetLength() + 1); } file.Close(); } return szResult; }
wstring Format(wstring szFormat, ...) { INT nLength = 400; LPWSTR szBuffer = (LPWSTR)malloc(sizeof(WCHAR) * nLength); va_list argptr; va_start(argptr, szFormat); for (;;) { HRESULT hResult = StringCchVPrintf(szBuffer, nLength - 1, szFormat.c_str(), argptr); if (hResult == S_OK) { break; } else if (hResult == STRSAFE_E_INSUFFICIENT_BUFFER) { nLength *= 2; szBuffer = (LPWSTR)realloc(szBuffer, nLength * sizeof(WCHAR)); } else { *szBuffer = L'\0'; break; } } va_end(argptr); wstring szResult(szBuffer); free(szBuffer); return szResult; }
static void test_CSize() { CSize empty; ok(empty.cx == 0, "Expected cx to be 0, was %ld\n", empty.cx); ok(empty.cy == 0, "Expected cy to be 0, was %ld\n", empty.cy); CSize szPointA(10, 25); SIZE sz; sz.cx = 10; sz.cy = 25; CSize szPointB(sz); POINT pt; pt.x = 10; pt.y = 25; CSize szPointC(pt); CPoint ptObject(10, 25); CSize szPointD(ptObject); DWORD dw = MAKELONG(10, 25); CSize szPointE(dw); ok_size(szPointA, szPointB); ok_size(szPointB, szPointC); ok_size(szPointC, szPointD); ok_size(szPointD, szPointE); ptObject = szPointA + pt; CPoint res(20,50); ok_point(ptObject, res); ptObject = szPointA - pt; res = CPoint(0, 0); ok_point(ptObject, res); CSize sz1(135, 135); CSize sz2(135, 135); ok_size(sz1, sz2); sz1 = CSize(222, 222); sz2 = CSize(111, 111); ok(sz1 != sz2, "Wrong size, expected '%s' NOT to equal '%s'\n", wine_dbgstr_size(&sz1), wine_dbgstr_size(&sz2)); sz1 = CSize(100, 100); sz2 = CSize(50, 25); sz1 += sz2; CSize szResult(150, 125); ok_size(sz1, szResult); sz1 = CSize(100, 100); SIZE sz3; sz3.cx = 50; sz3.cy = 25; sz1 += sz3; ok_size(sz1, szResult); sz1 = CSize(100, 100); sz1 -= sz2; szResult = CSize(50, 75); ok_size(sz1, szResult); sz3.cx = 50; sz3.cy = 25; sz1 = CSize(100, 100); sz1 -= sz3; ok_size(sz1, szResult); sz1 = CSize(100, 100); CSize szOut; szOut = sz1 + sz2; szResult = CSize(150, 125); ok_size(szOut, szResult); sz3.cx = 50; sz3.cy = 25; szOut = sz1 + sz3; ok_size(szOut, szResult); szOut = sz1 - sz2; szResult = CSize(50, 75); ok_size(szOut, szResult); sz3.cx = 50; sz3.cy = 25; szOut = sz1 - sz3; ok_size(szOut, szResult); szResult = CSize(-50, -75); szOut = -szOut; ok_size(szOut, szResult); RECT rc = { 1, 2, 3, 4 }; CRect rcres = sz1 + &rc; CRect rcexp(101, 102, 103, 104); ok_rect(rcexp, rcres); rcres = sz1 - &rc; rcexp = CRect(-99, -98, -97, -96); ok_rect(rcexp, rcres); }