osutil.c 818 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "precompile.h"
  2. #include "osutil.h"
  3. #include <TlHelp32.h>
  4. TOOLKIT_API int osutil_detect_unique_app(char **pNames, int nNum)
  5. {
  6. //const WCHAR *exe;
  7. HANDLE hSnapshot;
  8. int rc = TRUE;
  9. /*{
  10. WCHAR *t = (WCHAR*)_alloca(MAX_PATH);
  11. GetModuleFileNameW(NULL, t, MAX_PATH);
  12. exe = wcsrchr(t, '\\') + 1;
  13. }*/
  14. DWORD dwCurProcID = GetCurrentProcessId();
  15. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  16. if (hSnapshot) {
  17. PROCESSENTRY32 pe;
  18. pe.dwSize = sizeof(pe);
  19. if (Process32First(hSnapshot, &pe))
  20. {
  21. do
  22. {
  23. int i;
  24. for (i = 0; i < nNum; i++)
  25. {
  26. if (stricmp(&pe.szExeFile[0], pNames[i]) == 0 && pe.th32ProcessID != dwCurProcID)
  27. {
  28. rc = FALSE;
  29. break;
  30. }
  31. }
  32. } while (Process32Next(hSnapshot, &pe));
  33. }
  34. CloseHandle(hSnapshot);
  35. }
  36. return rc;
  37. }