Unsolved Qt can't find all the modules of program
-
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:
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.
-
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: