ReactOS 0.4.17-dev-116-ga4b6fe9
_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 94 of file comsupp.cpp.

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

◆ ConvertStringToBSTR()

BSTR WINAPI _com_util::ConvertStringToBSTR ( const char pSrc)

Definition at line 60 of file comsupp.cpp.

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