Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Win32ApiWinRTEmulation.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINRT
  3. #include "os/Win32/WindowsHeaders.h"
  4. #include <string>
  5. #include <windows.system.profile.h>
  6. #include <windows.system.userprofile.h>
  7. #include "os/Mutex.h"
  8. #include "SynchronousOperation.h"
  9. #include "utils/Il2CppHashMap.h"
  10. #include "utils/Memory.h"
  11. #include "utils/StringUtils.h"
  12. #include "Win32ApiSharedEmulation.h"
  13. #include "Win32ApiWinRTEmulation.h"
  14. #include "Baselib.h"
  15. #include "Cpp/ReentrantLock.h"
  16. using namespace ABI::Windows::Foundation;
  17. using namespace ABI::Windows::System::Profile;
  18. using namespace ABI::Windows::System::UserProfile;
  19. using namespace Microsoft::WRL;
  20. using namespace Microsoft::WRL::Wrappers;
  21. using namespace il2cpp::winrt;
  22. extern "C"
  23. {
  24. BOOL WINAPI GetUserNameW(LPWSTR lpBuffer, LPDWORD pcbBuffer)
  25. {
  26. #define ERROR_CHECK(hr) do { if (FAILED(hr)) { SetLastError(WIN32_FROM_HRESULT(hr)); return FALSE; } } while (false)
  27. ComPtr<IUserInformationStatics> info;
  28. auto hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_System_UserProfile_UserInformation).Get(), __uuidof(info), &info);
  29. ERROR_CHECK(hr);
  30. boolean isAccessAllowed;
  31. hr = info->get_NameAccessAllowed(&isAccessAllowed);
  32. ERROR_CHECK(hr);
  33. if (!isAccessAllowed)
  34. {
  35. SetLastError(ERROR_ACCESS_DENIED);
  36. return FALSE;
  37. }
  38. ComPtr<IAsyncOperation<HSTRING> > op;
  39. hr = info->GetDisplayNameAsync(&op);
  40. ERROR_CHECK(hr);
  41. HString name;
  42. hr = MakeSynchronousOperation(op.Get())->GetResults(name.GetAddressOf());
  43. ERROR_CHECK(hr);
  44. #undef ERROR_CHECK
  45. return CopyHStringToBuffer(name, lpBuffer, pcbBuffer);
  46. }
  47. } // extern "C"
  48. #endif