Introduces wxBSTR, an RAII wrapper for MSW BSTR type. wxBSTR also supersedes wxBasicString.
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
|
||||
WXDLLEXPORT BSTR wxConvertStringToOle(const wxString& str)
|
||||
{
|
||||
return wxBasicString(str).Get();
|
||||
return wxBSTR(str).Detach();
|
||||
}
|
||||
|
||||
WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr)
|
||||
@@ -68,28 +68,48 @@ WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBasicString
|
||||
// wxBSTR
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBasicString::wxBasicString(const wxString& str)
|
||||
{
|
||||
m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent));
|
||||
}
|
||||
|
||||
wxBasicString::wxBasicString(const wxBasicString& src)
|
||||
{
|
||||
m_bstrBuf = src.Get();
|
||||
}
|
||||
|
||||
wxBasicString& wxBasicString::operator=(const wxBasicString& src)
|
||||
{
|
||||
SysReAllocString(&m_bstrBuf, src);
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxBasicString::~wxBasicString()
|
||||
{
|
||||
SysFreeString(m_bstrBuf);
|
||||
wxBSTR::wxBSTR(BSTR bstr, bool copy)
|
||||
{
|
||||
if ( copy )
|
||||
m_bstr = ::SysAllocString(bstr);
|
||||
else
|
||||
m_bstr = bstr;
|
||||
}
|
||||
|
||||
wxBSTR& wxBSTR::operator=(const wxBSTR& wxbstr)
|
||||
{
|
||||
if ( wxbstr != *this )
|
||||
{
|
||||
Free();
|
||||
m_bstr = wxbstr.GetCopy();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxBSTR::Attach(BSTR bstr)
|
||||
{
|
||||
wxCHECK_RET(m_bstr != bstr, wxS("Attaching already attached BSTR!"));
|
||||
|
||||
Free();
|
||||
m_bstr = bstr;
|
||||
}
|
||||
|
||||
BSTR wxBSTR::Detach()
|
||||
{
|
||||
BSTR bstr = m_bstr;
|
||||
|
||||
m_bstr = NULL;
|
||||
return bstr;
|
||||
}
|
||||
|
||||
void wxBSTR::Free()
|
||||
{
|
||||
::SysFreeString(m_bstr);
|
||||
m_bstr = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user