DIAUtils.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DIAUtils.h - Utility functions for working with DIA ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
  14. #define LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/Support/ConvertUTF.h"
  17. template <typename Obj>
  18. std::string invokeBstrMethod(Obj &Object,
  19. HRESULT (__stdcall Obj::*Func)(BSTR *)) {
  20. CComBSTR Str16;
  21. HRESULT Result = (Object.*Func)(&Str16);
  22. if (S_OK != Result)
  23. return std::string();
  24. std::string Str8;
  25. llvm::ArrayRef<char> StrBytes(reinterpret_cast<char *>(Str16.m_str),
  26. Str16.ByteLength());
  27. llvm::convertUTF16ToUTF8String(StrBytes, Str8);
  28. return Str8;
  29. }
  30. #endif // LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
  31. #ifdef __GNUC__
  32. #pragma GCC diagnostic pop
  33. #endif