LLVM  8.0.1
DIAUtils.h
Go to the documentation of this file.
1 //===- DIAUtils.h - Utility functions for working with DIA ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
11 #define LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
12 
13 #include "llvm/ADT/ArrayRef.h"
15 
16 template <typename Obj>
17 std::string invokeBstrMethod(Obj &Object,
18  HRESULT (__stdcall Obj::*Func)(BSTR *)) {
19  CComBSTR Str16;
20  HRESULT Result = (Object.*Func)(&Str16);
21  if (S_OK != Result)
22  return std::string();
23 
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 
31 #endif // LLVM_DEBUGINFO_PDB_DIA_DIAUTILS_H
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
std::string invokeBstrMethod(Obj &Object, HRESULT(__stdcall Obj::*Func)(BSTR *))
Definition: DIAUtils.h:17
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.