Modify wxBasicString so it is better suited to work as an RAII wrapper for BSTR.
This commit is contained in:
@@ -71,20 +71,19 @@ WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr)
|
||||
// wxBasicString
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBasicString::wxBasicString(BSTR bstr)
|
||||
{
|
||||
m_bstrBuf = bstr;
|
||||
}
|
||||
|
||||
wxBasicString::wxBasicString(const wxString& str)
|
||||
{
|
||||
m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent));
|
||||
}
|
||||
|
||||
wxBasicString::wxBasicString(const wxBasicString& src)
|
||||
wxBasicString::wxBasicString(const wxBasicString& bstr)
|
||||
{
|
||||
m_bstrBuf = src.Get();
|
||||
}
|
||||
|
||||
wxBasicString& wxBasicString::operator=(const wxBasicString& src)
|
||||
{
|
||||
SysReAllocString(&m_bstrBuf, src);
|
||||
return *this;
|
||||
m_bstrBuf = bstr.Copy();
|
||||
}
|
||||
|
||||
wxBasicString::~wxBasicString()
|
||||
@@ -92,6 +91,43 @@ wxBasicString::~wxBasicString()
|
||||
SysFreeString(m_bstrBuf);
|
||||
}
|
||||
|
||||
wxBasicString& wxBasicString::operator=(const wxBasicString& src)
|
||||
{
|
||||
if ( this != &src )
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = src.Copy();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxBasicString& wxBasicString::operator=(const wxString& str)
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = ::SysAllocString(str.wc_str(*wxConvCurrent));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxBasicString& wxBasicString::operator=(BSTR bstr)
|
||||
{
|
||||
wxCHECK_MSG(m_bstrBuf != bstr, *this, wxS("Attempting to attach already attached BSTR!"));
|
||||
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = bstr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BSTR wxBasicString::Detach()
|
||||
{
|
||||
BSTR bstr = m_bstrBuf;
|
||||
|
||||
m_bstrBuf = NULL;
|
||||
|
||||
return bstr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Convert variants
|
||||
|
||||
Reference in New Issue
Block a user