changed session module name retrieval + name when wnd not shown
This commit is contained in:
parent
2a1b30e166
commit
5e5365274c
2 changed files with 18 additions and 30 deletions
|
|
@ -129,11 +129,14 @@ Session::Session(Endpoint* ep, IAudioSessionControl2* sessionControl, size_t idx
|
||||||
if (!wcscmp(sessionDisplayName, L"")) {
|
if (!wcscmp(sessionDisplayName, L"")) {
|
||||||
std::wstring exePath;
|
std::wstring exePath;
|
||||||
if (getExePath(pid, &exePath)) {
|
if (getExePath(pid, &exePath)) {
|
||||||
|
this->sessionName = exePath;
|
||||||
if (fetchName(exePath, pid)) goto nameFound;
|
if (fetchName(exePath, pid)) goto nameFound;
|
||||||
}
|
}
|
||||||
if (fetchNameViaWindowName(pid, &this->sessionName)) goto nameFound;
|
if (fetchNameViaWindowName(pid, &this->sessionName)) goto nameFound;
|
||||||
} else
|
} else {
|
||||||
this->sessionName = std::wstring(sessionDisplayName);
|
this->sessionName = std::wstring(sessionDisplayName);
|
||||||
|
goto nameFound;
|
||||||
|
}
|
||||||
|
|
||||||
nameFound:
|
nameFound:
|
||||||
CoTaskMemFree(sessionDisplayName);
|
CoTaskMemFree(sessionDisplayName);
|
||||||
|
|
@ -199,37 +202,21 @@ void Session::setMute(NGuid guid, bool muted) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Session::getExePath(DWORD pid, std::wstring *exePath) {
|
bool Session::getExePath(DWORD pid, std::wstring *exePath) {
|
||||||
/*
|
|
||||||
* https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
|
|
||||||
* https://stackoverflow.com/questions/11843368/how-to-get-process-description
|
|
||||||
* https://notes.indezine.com/2018/05/microsoft-locale-ids.html#:~:text=Wait%2C%201033%20is%20the%20decimal,ID%20for%20English%20%E2%80%93%20United%20States.
|
|
||||||
* https://stackoverflow.com/questions/64321036/c-win32-getting-app-name-using-pid-and-executable-path
|
|
||||||
*/
|
|
||||||
|
|
||||||
//std::wstring msixName;
|
//std::wstring msixName;
|
||||||
|
HANDLE processHandle;
|
||||||
HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
|
wchar_t fileName[UNICODE_STRING_MAX_CHARS];
|
||||||
if (processList == INVALID_HANDLE_VALUE) {
|
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
|
||||||
|
if (processHandle != NULL) {
|
||||||
|
if (GetModuleFileNameEx(processHandle, NULL, fileName, UNICODE_STRING_MAX_CHARS) == 0) {
|
||||||
|
CloseHandle(processHandle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
log_wdebugcpp(L"aye no procname. -> " + std::to_wstring(GetLastError()));
|
log_wdebugcpp(L"aye no procname. -> " + std::to_wstring(GetLastError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MODULEENTRY32W me32w;
|
*exePath = std::wstring(fileName);
|
||||||
me32w.dwSize = sizeof(MODULEENTRY32W);
|
|
||||||
if(Module32FirstW(processList, &me32w)) {
|
|
||||||
do {
|
|
||||||
if (me32w.th32ProcessID == pid) {
|
|
||||||
*exePath = std::wstring(me32w.szExePath);
|
|
||||||
break;
|
|
||||||
/*
|
|
||||||
* However, if the calling process is a 32-bit process, you must call the
|
|
||||||
* QueryFullProcessImageName function to retrieve the full path of the
|
|
||||||
* executable file for a 64-bit process.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
} while(Module32NextW(processList, &me32w));
|
|
||||||
}
|
|
||||||
CloseHandle(processList);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -362,8 +349,8 @@ bool Session::fetchNameViaWindowName(DWORD pid, std::wstring *sessionName) {
|
||||||
auto pParams = (std::pair<HWND, DWORD>*)(lParam);
|
auto pParams = (std::pair<HWND, DWORD>*)(lParam);
|
||||||
|
|
||||||
DWORD processId;
|
DWORD processId;
|
||||||
//&& GetWindow(hwnd, GW_OWNER) == 0
|
//IsWindowVisible(hwnd) &&&& GetWindow(hwnd, GW_OWNER) == 0
|
||||||
if (IsWindowVisible(hwnd) && GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
if ( GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
||||||
int length = GetWindowTextLength(hwnd);
|
int length = GetWindowTextLength(hwnd);
|
||||||
if (!length) return TRUE;
|
if (!length) return TRUE;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#include <Propidl.h>
|
#include <Propidl.h>
|
||||||
#include <propsys.h>
|
#include <propsys.h>
|
||||||
#include <functiondiscoverykeys_devpkey.h>
|
#include <functiondiscoverykeys_devpkey.h>
|
||||||
|
#include <psapi.h>
|
||||||
//#include <debugapi.h>
|
//#include <debugapi.h>
|
||||||
|
|
||||||
#include <endpointvolume.h>
|
#include <endpointvolume.h>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue