ReactOS  0.4.15-dev-5455-g015cd25
_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 93 of file comsupp.cpp.

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

◆ ConvertStringToBSTR()

BSTR WINAPI _com_util::ConvertStringToBSTR ( const char pSrc)

Definition at line 59 of file comsupp.cpp.

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