Simplify wxWebViewIE code further by using wxSafeArray<>.
Use the existing class instead of using SAFEARRAY directly.
See f5d2bfa880
.
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <mshtml.h>
|
#include <mshtml.h>
|
||||||
#include "wx/msw/registry.h"
|
#include "wx/msw/registry.h"
|
||||||
#include "wx/msw/missing.h"
|
#include "wx/msw/missing.h"
|
||||||
|
#include "wx/msw/ole/safearray.h"
|
||||||
#include "wx/filesys.h"
|
#include "wx/filesys.h"
|
||||||
#include "wx/dynlib.h"
|
#include "wx/dynlib.h"
|
||||||
#include "wx/scopeguard.h"
|
#include "wx/scopeguard.h"
|
||||||
@@ -146,74 +147,24 @@ void wxWebViewIE::LoadURL(const wxString& url)
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
// Simple RAII wrapper for accessing SAFEARRAY<VARIANT>. This class is not specific
|
|
||||||
// to wxWebView at all and could be extended to work for any type and extracted
|
|
||||||
// into a header later if it is ever needed elsewhere, but for now keep it here
|
|
||||||
// as it is only used in MakeOneElementVariantSafeArray() which, itself, is
|
|
||||||
// only used by DoSetPage() below.
|
|
||||||
class wxSafeArrayVariantAccessor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit wxSafeArrayVariantAccessor(SAFEARRAY* sa)
|
|
||||||
: m_sa(sa),
|
|
||||||
m_data(DoAccessData(sa))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VARIANT* GetData() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
~wxSafeArrayVariantAccessor()
|
|
||||||
{
|
|
||||||
if ( m_data )
|
|
||||||
SafeArrayUnaccessData(m_sa);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static VARIANT* DoAccessData(SAFEARRAY* sa)
|
|
||||||
{
|
|
||||||
VARIANT *param;
|
|
||||||
HRESULT hr = SafeArrayAccessData(sa, (LPVOID*)¶m);
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
wxLogLastError(wxT("SafeArrayAccessData"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return param;
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFEARRAY* const m_sa;
|
|
||||||
VARIANT* const m_data;
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(wxSafeArrayVariantAccessor);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function: wrap the given string in a SAFEARRAY<VARIANT> of size 1.
|
// Helper function: wrap the given string in a SAFEARRAY<VARIANT> of size 1.
|
||||||
SAFEARRAY* MakeOneElementVariantSafeArray(const wxString& str)
|
SAFEARRAY* MakeOneElementVariantSafeArray(const wxString& str)
|
||||||
{
|
{
|
||||||
SAFEARRAY* const sa = SafeArrayCreateVector(VT_VARIANT, 0, 1);
|
wxSafeArray<VT_VARIANT> sa;
|
||||||
if ( !sa )
|
if ( !sa.Create(1) )
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("SafeArrayCreateVector"));
|
wxLogLastError(wxT("SafeArrayCreateVector"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSafeArrayVariantAccessor access(sa);
|
long ind = 0;
|
||||||
|
if ( !sa.SetElement(&ind, str) )
|
||||||
VARIANT* const param = access.GetData();
|
|
||||||
if ( !param )
|
|
||||||
{
|
{
|
||||||
SafeArrayDestroy(sa);
|
wxLogLastError(wxT("SafeArrayPtrOfIndex"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
param->vt = VT_BSTR;
|
return sa.Detach();
|
||||||
param->bstrVal = SysAllocString(str.wc_str());
|
|
||||||
|
|
||||||
return sa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
Reference in New Issue
Block a user