MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / getLoadedModules

Function getLoadedModules

src/envmodule.cpp:427–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427std::vector<Module> getLoadedModules()
428{
429 HandlePtr snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE32 | TH32CS_SNAPMODULE,
430 GetCurrentProcessId()));
431
432 if (snapshot.get() == INVALID_HANDLE_VALUE) {
433 const auto e = GetLastError();
434 log::error("CreateToolhelp32Snapshot() failed, {}", formatSystemMessage(e));
435 return {};
436 }
437
438 MODULEENTRY32 me = {};
439 me.dwSize = sizeof(me);
440
441 // first module, this shouldn't fail because there's at least the executable
442 if (!Module32First(snapshot.get(), &me)) {
443 const auto e = GetLastError();
444 log::error("Module32First() failed, {}", formatSystemMessage(e));
445 return {};
446 }
447
448 std::vector<Module> v;
449
450 for (;;) {
451 const auto path = QString::fromWCharArray(me.szExePath);
452 if (!path.isEmpty()) {
453 v.push_back(Module(path, me.modBaseSize));
454 }
455
456 // next module
457 if (!Module32Next(snapshot.get(), &me)) {
458 const auto e = GetLastError();
459
460 // no more modules is not an error
461 if (e != ERROR_NO_MORE_FILES) {
462 log::error("Module32Next() failed, {}", formatSystemMessage(e));
463 }
464
465 break;
466 }
467 }
468
469 // sorting by display name
470 std::sort(v.begin(), v.end(), [](auto&& a, auto&& b) {
471 return (a.displayPath().compare(b.displayPath(), Qt::CaseInsensitive) < 0);
472 });
473
474 return v;
475}
476
477template <class F>
478void forEachRunningProcess(F&& f)

Callers 1

env.cppFile · 0.85

Calls 7

compareMethod · 0.80
displayPathMethod · 0.80
ModuleClass · 0.70
getMethod · 0.45
isEmptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected