Use wxCoTaskMemPtr
Use RAII class wxCoTaskMemPtr to manage pointers that must be freed with ::CoTaskMemFree().
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
#include "wx/msw/wrapshl.h"
|
#include "wx/msw/wrapshl.h"
|
||||||
|
#include "wx/msw/private/cotaskmemptr.h"
|
||||||
#include <initguid.h>
|
#include <initguid.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -171,12 +172,11 @@ wxString wxStandardPaths::DoGetKnownFolder(const GUID& rfid)
|
|||||||
|
|
||||||
if ( gs_shellFuncs.pSHGetKnownFolderPath )
|
if ( gs_shellFuncs.pSHGetKnownFolderPath )
|
||||||
{
|
{
|
||||||
PWSTR pDir;
|
wxCoTaskMemPtr<wchar_t> pDir;
|
||||||
HRESULT hr = gs_shellFuncs.pSHGetKnownFolderPath(rfid, 0, 0, &pDir);
|
HRESULT hr = gs_shellFuncs.pSHGetKnownFolderPath(rfid, 0, 0, &pDir);
|
||||||
if ( SUCCEEDED(hr) )
|
if ( SUCCEEDED(hr) )
|
||||||
{
|
{
|
||||||
dir = pDir;
|
dir = pDir;
|
||||||
CoTaskMemFree(pDir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "wx/msw/taskbarbutton.h"
|
#include "wx/msw/taskbarbutton.h"
|
||||||
#include "wx/scopedptr.h"
|
#include "wx/scopedptr.h"
|
||||||
#include "wx/msw/private/comptr.h"
|
#include "wx/msw/private/comptr.h"
|
||||||
|
#include "wx/msw/private/cotaskmemptr.h"
|
||||||
|
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#include <initguid.h>
|
#include <initguid.h>
|
||||||
@@ -498,10 +499,9 @@ wxTaskBarJumpListItem* GetItemFromIShellItem(IShellItem *shellItem)
|
|||||||
wxTaskBarJumpListItem *item =
|
wxTaskBarJumpListItem *item =
|
||||||
new wxTaskBarJumpListItem(NULL, wxTASKBAR_JUMP_LIST_DESTINATION);
|
new wxTaskBarJumpListItem(NULL, wxTASKBAR_JUMP_LIST_DESTINATION);
|
||||||
|
|
||||||
wchar_t *name;
|
wxCoTaskMemPtr<wchar_t> name;
|
||||||
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &name);
|
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &name);
|
||||||
item->SetFilePath(wxString(name));
|
item->SetFilePath(wxString(name));
|
||||||
CoTaskMemFree(name);
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
#include "wx/msw/private/winstyle.h"
|
#include "wx/msw/private/winstyle.h"
|
||||||
|
#include "wx/msw/private/cotaskmemptr.h"
|
||||||
|
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
#include "wx/msw/uxtheme.h"
|
#include "wx/msw/uxtheme.h"
|
||||||
@@ -207,13 +208,13 @@ public:
|
|||||||
|
|
||||||
const wxWX2WCbuf wcbuf = s.wc_str();
|
const wxWX2WCbuf wcbuf = s.wc_str();
|
||||||
const size_t size = (wcslen(wcbuf) + 1)*sizeof(wchar_t);
|
const size_t size = (wcslen(wcbuf) + 1)*sizeof(wchar_t);
|
||||||
void *olestr = CoTaskMemAlloc(size);
|
wxCoTaskMemPtr<wchar_t> olestr(size);
|
||||||
|
|
||||||
if ( !olestr )
|
if ( !olestr )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
memcpy(olestr, wcbuf, size);
|
memcpy(olestr, wcbuf, size);
|
||||||
|
*rgelt++ = olestr.release();
|
||||||
*rgelt++ = static_cast<LPOLESTR>(olestr);
|
|
||||||
|
|
||||||
++(*pceltFetched);
|
++(*pceltFetched);
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "wx/private/jsscriptwrapper.h"
|
#include "wx/private/jsscriptwrapper.h"
|
||||||
#include "wx/private/json.h"
|
#include "wx/private/json.h"
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
|
#include "wx/msw/private/cotaskmemptr.h"
|
||||||
#include "wx/msw/private/webview_edge.h"
|
#include "wx/msw/private/webview_edge.h"
|
||||||
|
|
||||||
#include <wrl/event.h>
|
#include <wrl/event.h>
|
||||||
@@ -124,16 +125,10 @@ bool wxWebViewEdgeImpl::Initialize()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if a Edge browser can be found by the loader DLL
|
// Check if a Edge browser can be found by the loader DLL
|
||||||
LPWSTR versionStr;
|
wxCoTaskMemPtr<wchar_t> versionStr;
|
||||||
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(NULL, &versionStr);
|
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(NULL, &versionStr);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr) && versionStr)
|
||||||
{
|
return true;
|
||||||
if (versionStr)
|
|
||||||
{
|
|
||||||
CoTaskMemFree(versionStr);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr);
|
wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr);
|
||||||
|
|
||||||
@@ -161,12 +156,10 @@ HRESULT wxWebViewEdgeImpl::OnNavigationStarting(ICoreWebView2* WXUNUSED(sender),
|
|||||||
{
|
{
|
||||||
m_isBusy = true;
|
m_isBusy = true;
|
||||||
wxString evtURL;
|
wxString evtURL;
|
||||||
LPWSTR uri;
|
wxCoTaskMemPtr<wchar_t> uri;
|
||||||
if (SUCCEEDED(args->get_Uri(&uri)))
|
if (SUCCEEDED(args->get_Uri(&uri)))
|
||||||
{
|
|
||||||
evtURL = wxString(uri);
|
evtURL = wxString(uri);
|
||||||
CoTaskMemFree(uri);
|
|
||||||
}
|
|
||||||
wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING, m_ctrl->GetId(), evtURL, wxString());
|
wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING, m_ctrl->GetId(), evtURL, wxString());
|
||||||
event.SetEventObject(m_ctrl);
|
event.SetEventObject(m_ctrl);
|
||||||
m_ctrl->HandleWindowEvent(event);
|
m_ctrl->HandleWindowEvent(event);
|
||||||
@@ -245,13 +238,10 @@ HRESULT wxWebViewEdgeImpl::OnNavigationCompleted(ICoreWebView2* WXUNUSED(sender)
|
|||||||
|
|
||||||
HRESULT wxWebViewEdgeImpl::OnNewWindowRequested(ICoreWebView2* WXUNUSED(sender), ICoreWebView2NewWindowRequestedEventArgs* args)
|
HRESULT wxWebViewEdgeImpl::OnNewWindowRequested(ICoreWebView2* WXUNUSED(sender), ICoreWebView2NewWindowRequestedEventArgs* args)
|
||||||
{
|
{
|
||||||
LPWSTR uri;
|
wxCoTaskMemPtr<wchar_t> uri;
|
||||||
wxString evtURL;
|
wxString evtURL;
|
||||||
if (SUCCEEDED(args->get_Uri(&uri)))
|
if (SUCCEEDED(args->get_Uri(&uri)))
|
||||||
{
|
|
||||||
evtURL = wxString(uri);
|
evtURL = wxString(uri);
|
||||||
CoTaskMemFree(uri);
|
|
||||||
}
|
|
||||||
wxWebViewNavigationActionFlags navFlags = wxWEBVIEW_NAV_ACTION_OTHER;
|
wxWebViewNavigationActionFlags navFlags = wxWEBVIEW_NAV_ACTION_OTHER;
|
||||||
|
|
||||||
BOOL isUserInitiated;
|
BOOL isUserInitiated;
|
||||||
@@ -519,26 +509,18 @@ bool wxWebViewEdge::IsBusy() const
|
|||||||
|
|
||||||
wxString wxWebViewEdge::GetCurrentURL() const
|
wxString wxWebViewEdge::GetCurrentURL() const
|
||||||
{
|
{
|
||||||
LPWSTR uri;
|
wxCoTaskMemPtr<wchar_t> uri;
|
||||||
if (m_impl->m_webView && SUCCEEDED(m_impl->m_webView->get_Source(&uri)))
|
if (m_impl->m_webView && SUCCEEDED(m_impl->m_webView->get_Source(&uri)))
|
||||||
{
|
return wxString(uri);
|
||||||
wxString uriStr(uri);
|
|
||||||
CoTaskMemFree(uri);
|
|
||||||
return uriStr;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return wxString();
|
return wxString();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxWebViewEdge::GetCurrentTitle() const
|
wxString wxWebViewEdge::GetCurrentTitle() const
|
||||||
{
|
{
|
||||||
LPWSTR title;
|
wxCoTaskMemPtr<wchar_t> title;
|
||||||
if (m_impl->m_webView && SUCCEEDED(m_impl->m_webView->get_DocumentTitle(&title)))
|
if (m_impl->m_webView && SUCCEEDED(m_impl->m_webView->get_DocumentTitle(&title)))
|
||||||
{
|
return wxString(title);
|
||||||
wxString titleStr(title);
|
|
||||||
CoTaskMemFree(title);
|
|
||||||
return titleStr;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return wxString();
|
return wxString();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user