[vlc-commits] [Git][videolan/vlc][master] 4 commits: nsis:/process: rework the way the process ID/HWND are handled
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Sep 27 14:28:18 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
0f8b7e83 by Steve Lhomme at 2023-09-27T14:01:55+00:00
nsis:/process: rework the way the process ID/HWND are handled
Don't use a HANDLE for both values, as structure with the proper type
works better.
- - - - -
ebcd76e1 by Steve Lhomme at 2023-09-27T14:01:55+00:00
nsis/process: fix warning on variable set and tested
- - - - -
bd0cc4e7 by Steve Lhomme at 2023-09-27T14:01:55+00:00
nsis/process: remove win95/98/ME support
We don't need these anymore.
- - - - -
95495e69 by Steve Lhomme at 2023-09-27T14:01:55+00:00
nsis/pluginapi: fix warning for declaration without parameters
- - - - -
2 changed files:
- extras/package/win32/NSIS/nsProcess/nsProcess.c
- extras/package/win32/NSIS/nsProcess/pluginapi.h
Changes:
=====================================
extras/package/win32/NSIS/nsProcess/nsProcess.c
=====================================
@@ -145,17 +145,23 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
return TRUE;
}
+struct win_id
+{
+ DWORD proc_id;
+ HWND prev_hwnd;
+};
+
BOOL CALLBACK EnumWindowsProc( HWND hwnd,
LPARAM lParam
)
{
- HANDLE *data = lParam;
+ struct win_id *data = (struct win_id *)lParam;
DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);
- if (pid == data[0])
+ if (pid == data->proc_id)
{
- PostMessage(data[1], WM_CLOSE, 0, 0);
- data[1] = hwnd;
+ PostMessage(data->prev_hwnd, WM_CLOSE, 0, 0);
+ data->prev_hwnd = hwnd;
}
return TRUE;
}
@@ -163,17 +169,15 @@ BOOL CALLBACK EnumWindowsProc( HWND hwnd,
void NiceTerminate(DWORD id, BOOL bClose, BOOL *bSuccess, BOOL *bFailed)
{
HANDLE hProc;
- HANDLE data[2];
DWORD ec;
BOOL bDone = FALSE;
- if (hProc=OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, id))
+ if ((hProc=OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, id)) != NULL)
{
- data[0] = id;
- data[1] = NULL;
+ struct win_id window = { id, NULL };
if (bClose)
- EnumWindows(EnumWindowsProc, data);
- if (data[1] != NULL)
+ EnumWindows(EnumWindowsProc, (LPARAM)&window);
+ if (window.prev_hwnd != NULL)
{
if (GetExitCodeProcess(hProc,&ec) && ec == STILL_ACTIVE)
if (WaitForSingleObject(hProc, 3000) == WAIT_OBJECT_0)
@@ -277,7 +281,7 @@ int FIND_PROC_BY_NAME(TCHAR *szProcessName, BOOL bTerminate, BOOL bClose)
DWORD dwData;
ULONG (WINAPI *NtQuerySystemInformationPtr)(ULONG, PVOID, LONG, PULONG);
- if (hLib=LoadLibraryW(L"NTDLL.DLL"))
+ if ((hLib=LoadLibraryW(L"NTDLL.DLL")) != NULL)
{
NtQuerySystemInformationPtr=(ULONG(WINAPI *)(ULONG, PVOID, LONG, PULONG))GetProcAddress(hLib, "NtQuerySystemInformation");
@@ -285,7 +289,7 @@ int FIND_PROC_BY_NAME(TCHAR *szProcessName, BOOL bTerminate, BOOL bClose)
{
while (1)
{
- if (spi=LocalAlloc(LMEM_FIXED, dwSize))
+ if ((spi=LocalAlloc(LMEM_FIXED, dwSize)) != NULL)
{
uError=(*NtQuerySystemInformationPtr)(SystemProcessInformation, spi, dwSize, &dwData);
@@ -345,72 +349,6 @@ int FIND_PROC_BY_NAME(TCHAR *szProcessName, BOOL bTerminate, BOOL bClose)
}
LocalFree(spi);
}
- else
- {
- // Win95/98/ME
-
- PROCESSENTRY32 pe;
- char *pName;
- HANDLE hSnapShot;
- BOOL bResult;
- HANDLE (WINAPI *CreateToolhelp32SnapshotPtr)(DWORD, DWORD);
- BOOL (WINAPI *Process32FirstPtr)(HANDLE, LPPROCESSENTRY32);
- BOOL (WINAPI *Process32NextPtr)(HANDLE, LPPROCESSENTRY32);
-
- if (hLib=LoadLibraryA("KERNEL32.DLL"))
- {
- CreateToolhelp32SnapshotPtr=(HANDLE(WINAPI *)(DWORD, DWORD)) GetProcAddress(hLib, "CreateToolhelp32Snapshot");
- Process32FirstPtr=(BOOL(WINAPI *)(HANDLE, LPPROCESSENTRY32)) GetProcAddress(hLib, "Process32First");
- Process32NextPtr=(BOOL(WINAPI *)(HANDLE, LPPROCESSENTRY32)) GetProcAddress(hLib, "Process32Next");
-
- if (CreateToolhelp32SnapshotPtr && Process32NextPtr && Process32FirstPtr)
- {
- // Get a handle to a Toolhelp snapshot of all the systems processes.
- if ((hSnapShot=(*CreateToolhelp32SnapshotPtr)(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
- {
- // Get the first process' information.
- pe.dwSize=sizeof(PROCESSENTRY32);
- bResult=(*Process32FirstPtr)(hSnapShot, &pe);
-
- // While there are processes, keep looping and checking.
- while (bResult)
- {
- //Get file name
- for (pName=pe.szExeFile + lstrlen(pe.szExeFile) - 1; *pName != '\\' && *pName != '\0'; --pName);
-
- ++pName;
-
-#ifdef UNICODE
- MultiByteToWideChar(CP_ACP, 0, pName, lstrlenA(pName)+1, szName, MAX_PATH);
-#else
- lstrcpyn(szName, pName, MAX_PATH);
-#endif
-
- if (!lstrcmpi(szName, szProcessName))
- {
- // Process found
- bFound=TRUE;
-
- if (bTerminate == TRUE)
- {
- // Open for termination
- NiceTerminate(pe.th32ProcessID, bClose, &bSuccess, &bFailed);
- }
- else break;
- }
- //Keep looking
- bResult=(*Process32NextPtr)(hSnapShot, &pe);
- }
- CloseHandle(hSnapShot);
- }
- else uError=611;
- }
- else uError=610;
-
- FreeLibrary(hLib);
- }
- else uError=609;
- }
if (bFound == FALSE) return 603;
if (bTerminate == TRUE)
=====================================
extras/package/win32/NSIS/nsProcess/pluginapi.h
=====================================
@@ -58,8 +58,8 @@ extern TCHAR *g_variables;
int NSISCALL popstring(TCHAR *str); // 0 on success, 1 on empty stack
int NSISCALL popstringn(TCHAR *str, int maxlen); // with length limit, pass 0 for g_stringsize
-int NSISCALL popint(); // pops an integer
-int NSISCALL popint_or(); // with support for or'ing (2|4|8)
+int NSISCALL popint(void); // pops an integer
+int NSISCALL popint_or(void); // with support for or'ing (2|4|8)
int NSISCALL myatoi(const TCHAR *s); // converts a string to an integer
unsigned NSISCALL myatou(const TCHAR *s); // converts a string to an unsigned integer, decimal only
int NSISCALL myatoi_or(const TCHAR *s); // with support for or'ing (2|4|8)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d13608f8867b66dec2e8079b4d07d1b8567ffa0a...95495e69b078381699f8eea6ba0c49bbd57c052a
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d13608f8867b66dec2e8079b4d07d1b8567ffa0a...95495e69b078381699f8eea6ba0c49bbd57c052a
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list