SkHRESULT.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2011 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkTypes.h"
  8. #if defined(SK_BUILD_FOR_WIN)
  9. #include "src/utils/win/SkHRESULT.h"
  10. void SkTraceHR(const char* file, unsigned long line, HRESULT hr, const char* msg) {
  11. if (msg) {
  12. SkDebugf("%s\n", msg);
  13. }
  14. SkDebugf("%s(%lu) : error 0x%x: ", file, line, hr);
  15. LPSTR errorText = nullptr;
  16. FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  17. FORMAT_MESSAGE_FROM_SYSTEM |
  18. FORMAT_MESSAGE_IGNORE_INSERTS,
  19. nullptr,
  20. hr,
  21. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  22. (LPSTR) &errorText,
  23. 0,
  24. nullptr
  25. );
  26. if (nullptr == errorText) {
  27. SkDebugf("<unknown>\n");
  28. } else {
  29. SkDebugf("%s", errorText);
  30. LocalFree(errorText);
  31. errorText = nullptr;
  32. }
  33. }
  34. #endif//defined(SK_BUILD_FOR_WIN)