Get all running objects from the Windows running object table. Save them in a map by their display names.
| 249 | //! Get all running objects from the Windows running object table. |
| 250 | //! Save them in a map by their display names. |
| 251 | HRESULT GetRunningInstances(std::map<std::string, IUnknownPtr>& mrot) |
| 252 | { |
| 253 | // mrot == Map of the Running Object Table |
| 254 | |
| 255 | IRunningObjectTablePtr runningObjectTable; |
| 256 | IEnumMonikerPtr monikerEnumerator; |
| 257 | IMonikerPtr moniker; |
| 258 | ULONG numFetched = 0; |
| 259 | |
| 260 | HRESULT hr = GetRunningObjectTable(0, &runningObjectTable); |
| 261 | ReportHRESULT(hr, "GetRunningObjectTable"); |
| 262 | |
| 263 | if (SUCCEEDED(hr)) { |
| 264 | hr = runningObjectTable->EnumRunning(&monikerEnumerator); |
| 265 | ReportHRESULT(hr, "EnumRunning"); |
| 266 | } |
| 267 | |
| 268 | if (SUCCEEDED(hr)) { |
| 269 | hr = monikerEnumerator->Reset(); |
| 270 | ReportHRESULT(hr, "Reset"); |
| 271 | } |
| 272 | |
| 273 | if (SUCCEEDED(hr)) { |
| 274 | while (S_OK == monikerEnumerator->Next(1, &moniker, &numFetched)) { |
| 275 | std::string runningObjectName; |
| 276 | IUnknownPtr runningObjectVal; |
| 277 | IBindCtxPtr ctx; |
| 278 | |
| 279 | hr = CreateBindCtx(0, &ctx); |
| 280 | ReportHRESULT(hr, "CreateBindCtx"); |
| 281 | |
| 282 | if (SUCCEEDED(hr)) { |
| 283 | LPOLESTR displayName = 0; |
| 284 | hr = moniker->GetDisplayName(ctx, 0, &displayName); |
| 285 | ReportHRESULT(hr, "GetDisplayName"); |
| 286 | if (displayName) { |
| 287 | runningObjectName = (std::string)(_bstr_t)displayName; |
| 288 | CoTaskMemFree(displayName); |
| 289 | } |
| 290 | |
| 291 | hr = runningObjectTable->GetObject(moniker, &runningObjectVal); |
| 292 | ReportHRESULT(hr, "GetObject"); |
| 293 | if (SUCCEEDED(hr)) { |
| 294 | mrot.insert(std::make_pair(runningObjectName, runningObjectVal)); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | numFetched = 0; |
| 299 | moniker = 0; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return hr; |
| 304 | } |
| 305 | |
| 306 | //! Do the two file names refer to the same Visual Studio solution? Or are |
| 307 | //! we perhaps looking for any and all solutions? |
no test coverage detected
searching dependent graphs…