Process.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINRT || IL2CPP_TARGET_XBOXONE
  3. #include "os/Win32/WindowsHeaders.h"
  4. #include "os/Process.h"
  5. #include "utils/Il2CppError.h"
  6. #include "utils/StringUtils.h"
  7. struct ProcessHandle
  8. {
  9. HANDLE handle;
  10. };
  11. namespace il2cpp
  12. {
  13. namespace os
  14. {
  15. int Process::GetCurrentProcessId()
  16. {
  17. return ::GetCurrentProcessId();
  18. }
  19. utils::Expected<ProcessHandle*> Process::GetProcess(int processId)
  20. {
  21. if (processId == GetCurrentProcessId())
  22. return (ProcessHandle*)::GetCurrentProcess();
  23. return utils::Il2CppError(utils::NotSupported, "It is not possible to interact with other system processes on current platform.");
  24. }
  25. void Process::FreeProcess(ProcessHandle* handle)
  26. {
  27. // We have nothing to do here.
  28. }
  29. utils::Expected<std::string> Process::GetProcessName(ProcessHandle* handle)
  30. {
  31. if (handle == ::GetCurrentProcess())
  32. {
  33. wchar_t path[MAX_PATH + 1];
  34. SetLastError(ERROR_SUCCESS);
  35. DWORD pathLength = GetModuleFileNameW(NULL, path, MAX_PATH + 1);
  36. return utils::StringUtils::Utf16ToUtf8(path, static_cast<int>(pathLength));
  37. }
  38. return utils::Il2CppError(utils::NotSupported, "It is not possible to interact with other system processes on current platform.");
  39. }
  40. intptr_t Process::GetMainWindowHandle(int32_t pid)
  41. {
  42. return 0;
  43. }
  44. }
  45. }
  46. #endif