ReactOS  0.4.12-dev-75-g00dd17e
_com_util Namespace Reference

Functions

BSTR WINAPI ConvertStringToBSTR (const char *pSrc)
 
char *WINAPI ConvertBSTRToString (BSTR pSrc)
 

Function Documentation

◆ ConvertBSTRToString()

char* WINAPI _com_util::ConvertBSTRToString ( BSTR  pSrc)

Definition at line 92 of file comsupp.cpp.

93 {
94  DWORD cb, cwch;
95  char *szOut = NULL;
96 
97  if (!pSrc) return NULL;
98 
99  /* Retrieve the size of the BSTR with the NULL terminator */
100  cwch = ::SysStringLen(pSrc) + 1;
101 
102  /* Compute the needed size with the NULL terminator */
103  cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, NULL, 0, NULL, NULL);
104  if (cb == 0)
105  {
106  cwch = ::GetLastError();
107  ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
108  return NULL;
109  }
110 
111  /* Allocate the string */
112  szOut = (char*)::operator new(cb * sizeof(char));
113  if (!szOut)
114  {
116  return NULL;
117  }
118 
119  /* Convert the string and NULL-terminate */
120  szOut[cb - 1] = '\0';
121  if (::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, szOut, cb, NULL, NULL) == 0)
122  {
123  /* We failed, clean everything up */
124  cwch = ::GetLastError();
125 
126  ::operator delete(szOut);
127  szOut = NULL;
128 
129  ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
130  }
131 
132  return szOut;
133 }
void WINAPI _com_issue_error(HRESULT hr)
Definition: comsupp.cpp:31
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
operator
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD cb
Definition: integrity.c:41
UINT WINAPI SysStringLen(BSTR str)
Definition: oleaut.c:200
#define IS_ERROR(stat)
Definition: winerror.h:74
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ ConvertStringToBSTR()

BSTR WINAPI _com_util::ConvertStringToBSTR ( const char pSrc)

Definition at line 58 of file comsupp.cpp.

59 {
60  DWORD cwch;
61  BSTR wsOut(NULL);
62 
63  if (!pSrc) return NULL;
64 
65  /* Compute the needed size with the NULL terminator */
66  cwch = ::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, NULL, 0);
67  if (cwch == 0) return NULL;
68 
69  /* Allocate the BSTR (without the NULL terminator) */
70  wsOut = ::SysAllocStringLen(NULL, cwch - 1);
71  if (!wsOut)
72  {
74  return NULL;
75  }
76 
77  /* Convert the string */
78  if (::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, wsOut, cwch) == 0)
79  {
80  /* We failed, clean everything up */
81  cwch = ::GetLastError();
82 
83  ::SysFreeString(wsOut);
84  wsOut = NULL;
85 
86  ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
87  }
88 
89  return wsOut;
90 }
void WINAPI _com_issue_error(HRESULT hr)
Definition: comsupp.cpp:31
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:343
#define CP_ACP
Definition: compat.h:99
void WINAPI SysFreeString(BSTR str)
Definition: oleaut.c:275
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
OLECHAR * BSTR
Definition: compat.h:1927
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IS_ERROR(stat)
Definition: winerror.h:74
#define MultiByteToWideChar
Definition: compat.h:100
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13