Make wxBasicString as simple and safe to use as possible
Don't try to write a general purpose class, but provide just the methods
that we need in our code.
This fixes the bug added in 294436c8bb
which resulted in a crash because a literal string, not a BSTR, was
passed to wxBasicString ctor.
This commit is contained in:
@@ -70,27 +70,12 @@ 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& bstr)
|
||||
{
|
||||
m_bstrBuf = bstr.Copy();
|
||||
}
|
||||
|
||||
wxBasicString::~wxBasicString()
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
}
|
||||
|
||||
void wxBasicString::AssignFromString(const wxString& str)
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent));
|
||||
}
|
||||
|
||||
BSTR wxBasicString::Detach()
|
||||
{
|
||||
BSTR bstr = m_bstrBuf;
|
||||
@@ -100,12 +85,6 @@ BSTR wxBasicString::Detach()
|
||||
return bstr;
|
||||
}
|
||||
|
||||
void wxBasicString::Free()
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = NULL;
|
||||
}
|
||||
|
||||
BSTR* wxBasicString::ByRef()
|
||||
{
|
||||
wxASSERT_MSG(!m_bstrBuf,
|
||||
@@ -126,25 +105,6 @@ wxBasicString& wxBasicString::operator=(const wxBasicString& src)
|
||||
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 == NULL || m_bstrBuf != bstr,
|
||||
*this, wxS("Attempting to assign already owned BSTR"));
|
||||
|
||||
SysFreeString(m_bstrBuf);
|
||||
m_bstrBuf = bstr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Convert variants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user