static void test_StrToIntExW(void) { WCHAR szBuff[256]; const StrToIntResult *result = StrToInt_results; int return_val; BOOL bRet; while (result->string) { return_val = -1; MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR)); bRet = StrToIntExW(szBuff, 0, &return_val); ok(!bRet || return_val != -1, "No result returned from '%s'\n", result->string); if (bRet) ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n", result->string, return_val); result++; } result = StrToInt_results; while (result->string) { return_val = -1; MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR)); bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val); ok(!bRet || return_val != -1, "No result returned from '%s'\n", result->string); if (bRet) ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n", result->string, return_val); result++; } }
CMarkdown::HSTR CMarkdown::_HSTR::Resolve(const EntityMap &map) { HSTR H = this; BSTR p, q = H->B; while ((p = StrChrW(q, '&')) != NULL && (q = StrChrW(p, ';')) != NULL) { *q = '\0'; OLECHAR *key = p + 1; std::wstring value; if (*key == '#') { int ordinal = '?'; *key = '0'; if (StrToIntExW(key, STIF_SUPPORT_HEX, &ordinal)) value.assign(1, (OLECHAR)ordinal); *key = '#'; } else { EntityMap::const_iterator p = map.find(key); if (p != map.end()) value = p->second; } *q = ';'; ++q; if (int cchValue = value.length()) { int i = p - H->B; int j = q - H->B; int cchKey = q - p; if (int cchGrow = cchValue - cchKey) { BSTR B = H->B; int b = SysStringLen(B); size_t cbMove = (b - j) * sizeof(OLECHAR); if (cchGrow < 0) { memmove(q + cchGrow, q, cbMove); } if (!SysReAllocStringLen(&B, B, b + cchGrow)) { continue; } H = (HSTR)B; p = H->B + i; q = H->B + j; if (cchGrow > 0) { memmove(q + cchGrow, q, cbMove); } } memcpy(p, value.c_str(), cchValue * sizeof(OLECHAR)); q = p + cchValue; } } return H; }
void CRemoteGraphForm::OnRefreshClick() { // let's load objects from ROT CComPtr<IRunningObjectTable> rot; HRESULT hr; graphs.RemoveAll(); list_graphs.DeleteAllItems(); sel_graph = RemoteGraph(); hr = GetRunningObjectTable(0, &rot); if (FAILED(hr)) return ; // scan through running objects CComPtr<IEnumMoniker> emon; CComPtr<IMoniker> moniker; CComPtr<IBindCtx> bindctx; ULONG f; hr = CreateBindCtx(0, &bindctx); if (FAILED(hr)) { return ; } CAtlRegExp<> regex; REParseError status = regex.Parse(_T("^\\!FilterGraph {[0-9A-F]+} pid {[0-9A-F]+}(; process\\: {.+?}, time\\: {[0-9]+\\-[0-9]+\\-[0-9]+})?"), FALSE); rot->EnumRunning(&emon); emon->Reset(); while (emon->Next(1, &moniker, &f) == NOERROR) { // is this a graph object ? LPOLESTR displayname; moniker->GetDisplayName(bindctx, NULL, &displayname); CString name(displayname); if (name.Find(_T("!FilterGraph")) == 0 && !GraphStudio::DisplayGraph::IsOwnRotGraph(name)) { RemoteGraph gr = {0}; CAtlREMatchContext<> mc; gr.name = name; gr.moniker = moniker; gr.pid = 0; gr.instance = 0; gr.processIsWOW64 = FALSE; if (regex.Match(name, &mc)) { const CAtlREMatchContext<>::RECHAR* szStart = 0; const CAtlREMatchContext<>::RECHAR* szEnd = 0; mc.GetMatch(0, &szStart, &szEnd); int nLength = (int) (szEnd - szStart); const CString textInstance(szStart, nLength); StrToInt64ExW(CStringW(L"0x") + textInstance, STIF_SUPPORT_HEX, &reinterpret_cast<LONGLONG&>(gr.instance)); mc.GetMatch(1, &szStart, &szEnd); nLength = (int) (szEnd - szStart); const CString textPID(szStart, nLength); CString nameSuffix(szEnd ? szEnd : _T("")); nameSuffix.Trim(); if (StrToIntExW(CStringW(L"0x") + textPID, STIF_SUPPORT_HEX, &reinterpret_cast<INT&>(gr.pid))) { CHandle process; process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, gr.pid)); if (process) { TCHAR pszPath[MAX_PATH] = { 0 }; if (GetModuleFileNameEx(process, NULL, pszPath, sizeof(pszPath))) { gr.processImagePath = pszPath; // Extract filename int fileNamePos = gr.processImagePath.FindFileName(); if (fileNamePos >= 0) gr.processImageFileName = CString(gr.processImagePath).Mid(fileNamePos); } else { // a 32Bit process can't list the modules of a 64Bit process, so try to get the processImageFileName from the ROT-Name (works only for FilterGraphSpy-Entries) mc.GetMatch(2, &szStart, &szEnd); nLength = (int) (szEnd - szStart); if (nLength > 0) { CString textFileName(szStart, nLength); gr.processImageFileName = textFileName; } else if (nameSuffix.GetLength() > 0) { gr.processImageFileName = nameSuffix; // as a last resort add any suffix information from the ROT name rather than leaving blank #ifndef _WIN64 gr.processImageFileName += _T(" *64"); // If we're 32bit, assume that we can't get process name because remote process is 64bit and show this on the dialog #endif } } IsWow64Process(process, &gr.processIsWOW64); } } mc.GetMatch(3, &szStart, &szEnd); nLength = (int) (szEnd - szStart); if (nLength > 0) { CString textTime(szStart, nLength); textTime.Replace(_T("-"), _T(":")); gr.time = textTime; } } graphs.Add(gr); CString entryName = gr.name; if (gr.pid > 0) entryName.Format(_T("%d (0x%08lX)"), gr.pid, gr.pid); int nIndex = list_graphs.InsertItem(list_graphs.GetItemCount(), entryName); if (gr.processIsWOW64) { CString val = gr.processImageFileName; val.Append(_T(" *32")); list_graphs.SetItemText(nIndex, 1, val); } else list_graphs.SetItemText(nIndex, 1, gr.processImageFileName); if (gr.instance > 0) { CString val; val.Format(_T("0x%I64d"), gr.instance); list_graphs.SetItemText(nIndex, 2, val); } list_graphs.SetItemText(nIndex, 3, gr.time); list_graphs.SetItemText(nIndex, 4, gr.processImagePath); if (graphs.GetCount() == 1) { list_graphs.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED); list_graphs.SetSelectionMark(0); } } if (displayname) { CComPtr<IMalloc> alloc; if (SUCCEEDED(CoGetMalloc(0, &alloc))) { alloc->Free(displayname); } } moniker = NULL; } // Set column width automatically to fit contents refreshed above for (int n=0; n<=4; n++) { list_graphs.SetColumnWidth(n, LVSCW_AUTOSIZE_USEHEADER); } }