Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt can't find all the modules of program
Forum Updated to NodeBB v4.3 + New Features

Qt can't find all the modules of program

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 470 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    Hi everyone. Here is the thing. I just started not such long ago exploring modules, and with help of MSDN example - i found all the modules of chosen program and print it's names on screen. In VS2017 it worked, so i implemented the same in Qt, mostly just copy whole thing from VS. And it also worked, but differently.

    Here is the function i'm use for test which gives such different results in 2 IDEs: https://docs.microsoft.com/en-us/windows/desktop/api/Psapi/nf-psapi-enumprocessmodules

    In VS it found 7 modules, in qt only 5, and i notice that some of .dlls which found qt - was'nt found in VS. Then i even create my testik.dll for my test program, and it also was'nt found, take a look:

    alt text

    I totally don't understand why this happened, code in both IDE pretty simple.

    The main question of this topic - why the result of EnumProcessModules function is different in this two IDE, when the code is absolutely the same(even variable names are the same). And the second question - why GetModuleBaseNameA return different modules.

    Full code in second post below.

    1 Reply Last reply
    0
    • EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by Engelard
      #2

      Here is the code in VS:

      int main()
      {
          HMODULE modArr[1024];
      
          unsigned int tital = 0;
          DWORD cbNeeded = 0;
      
          HWND hw = FindWindow(NULL, TEXT("DLLtests.exe"));
          if(hw != NULL)
          {
              DWORD objID;
              GetWindowThreadProcessId(hw, &objID);
              HANDLE someHandle = OpenProcess(PROCESS_ALL_ACCESS, false, objID);
      
              if(someHandle != NULL)
              {
                  if(EnumProcessModules(someHandle, modArr, sizeof(modArr), &cbNeeded))
                  {
                      tital = cbNeeded / sizeof(HMODULE);
                      cbNeeded = 0;
                      cout << "Modules: " << tital << endl<<endl;
      
                      for(int i = 0; i < tital; i++)
                      {
                          char tempSTR[32];
                          unsigned int cnt = 0;
      
                          if(cnt = GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR)) != 0)
                          {
                              cout << i+1<< ": "<< tempSTR << endl;
                          }
                      }
                  }
                  else { cout << "FAIL-1" << endl; }
              }
              else { cout << "FAIL-2" << endl; }
      
              CloseHandle(someHandle);
          }
          else { cout << "FAIL-3" << endl; }
      
          cin.get();
      }
      

      And here the same in Qt:

      void MWindow::printModules(DWORD id)
      {
          HMODULE modArr[1024];
      
          unsigned int tital = 0;
          DWORD cbNeeded = 0;
      
          HANDLE someHandle = OpenProcess(PROCESS_ALL_ACCESS, false, id);
      
          if(someHandle != NULL)
          {
              if(EnumProcessModules(someHandle, modArr, sizeof(modArr), &cbNeeded))
              {
                  tital = cbNeeded / sizeof(HMODULE);
                  ui->textBrowser1->append("Modules: "+QString::number(tital));
                  ui->textBrowser1->append(" ");
      
                  for(int i = 0; i < tital; i++)
                  {
                      char tempSTR[32];
                      unsigned int cnt = 0;
      
                      if(cnt = GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR)) != 0)
                      {
                          ui->textBrowser1->append(QString::number(i+1)+": "+QString::fromLatin1(tempSTR));
                      }
                  }
              }
              else { ui->textBrowser1->append("FAIL-1"); }
          }
          else { ui->textBrowser1->append("FAIL-2"); }
      
          CloseHandle(someHandle);
      }
      

      And results are different:

      alt text

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved