summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@digia.com>2014-05-23 17:16:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-03 09:55:30 +0200
commit6b9a9a01e289381ea915ac43595c6c5da0db73b4 (patch)
tree68f460051ea2e42af8b5d6c7331ad5218cc1e68c
parent69e2d3b3e96bb1fa553acb5cd867267d1596c314 (diff)
remove HSTRING instances
HSTRING needs to be released or handles will be leaked. Instead use HString which takes care of resource management on its own. Task-Number: QTBUG-38115 Change-Id: I2c767776c1f22f45acd8dd77b693f30d63d894b9 Reviewed-by: Andrew Knight <andrew.knight@digia.com> Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp12
-rw-r--r--src/corelib/io/qsettings.cpp6
-rw-r--r--src/corelib/io/qstandardpaths_winrt.cpp6
-rw-r--r--src/corelib/tools/qlocale_win.cpp6
-rw-r--r--src/network/kernel/qdnslookup_winrt.cpp12
-rw-r--r--src/network/kernel/qhostinfo_winrt.cpp24
-rw-r--r--src/network/kernel/qnetworkinterface_winrt.cpp6
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp56
-rw-r--r--src/plugins/platforms/winrt/qwinrtplatformmessagedialoghelper.cpp7
-rw-r--r--src/plugins/platforms/winrt/qwinrtservices.cpp15
-rw-r--r--src/winmain/qtmain_winrt.cpp9
11 files changed, 82 insertions, 77 deletions
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index 8e3bacd6b7..1d79136422 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -1219,11 +1219,11 @@ QString QFileSystemEngine::rootPath()
if (FAILED(installedLocation.As(&item)))
return ret;
- HSTRING finalWinPath;
- if (FAILED(item->get_Path(&finalWinPath)))
+ HString finalWinPath;
+ if (FAILED(item->get_Path(finalWinPath.GetAddressOf())))
return ret;
- ret = QDir::fromNativeSeparators(QString::fromWCharArray(WindowsGetStringRawBuffer(finalWinPath, nullptr)));
+ ret = QDir::fromNativeSeparators(QString::fromWCharArray(finalWinPath.GetRawBuffer(nullptr)));
#else
QString ret = QString::fromLatin1(qgetenv("SystemDrive").constData());
@@ -1319,10 +1319,10 @@ QString QFileSystemEngine::tempPath()
ComPtr<IStorageItem> tempFolderItem;
if (FAILED(tempFolder.As(&tempFolderItem)))
return ret;
- HSTRING path;
- if (FAILED(tempFolderItem->get_Path(&path)))
+ HString path;
+ if (FAILED(tempFolderItem->get_Path(path.GetAddressOf())))
return ret;
- ret = QDir::fromNativeSeparators(QString::fromWCharArray(WindowsGetStringRawBuffer(path, nullptr)));
+ ret = QDir::fromNativeSeparators(QString::fromWCharArray(path.GetRawBuffer(nullptr)));
#endif // Q_OS_WINRT
if (ret.isEmpty()) {
#if !defined(Q_OS_WINCE)
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index 63a0266948..7b4240e102 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -1084,10 +1084,10 @@ static QString windowsConfigPath(int type)
ComPtr<IStorageItem> localFolderItem;
if (FAILED(localFolder.As(&localFolderItem)))
return result;
- HSTRING path;
- if (FAILED(localFolderItem->get_Path(&path)))
+ HString path;
+ if (FAILED(localFolderItem->get_Path(path.GetAddressOf())))
return result;
- result = QString::fromWCharArray(WindowsGetStringRawBuffer(path, nullptr));
+ result = QString::fromWCharArray(path.GetRawBuffer(nullptr));
}
switch (type) {
diff --git a/src/corelib/io/qstandardpaths_winrt.cpp b/src/corelib/io/qstandardpaths_winrt.cpp
index bd72de11bb..84a3930ee0 100644
--- a/src/corelib/io/qstandardpaths_winrt.cpp
+++ b/src/corelib/io/qstandardpaths_winrt.cpp
@@ -89,10 +89,10 @@ QString QStandardPaths::writableLocation(StandardLocation type)
ComPtr<IStorageItem> settingsFolderItem;
if (FAILED(settingsFolder.As(&settingsFolderItem)))
break;
- HSTRING path;
- if (FAILED(settingsFolderItem->get_Path(&path)))
+ HString path;
+ if (FAILED(settingsFolderItem->get_Path(path.GetAddressOf())))
break;
- result = convertCharArray(WindowsGetStringRawBuffer(path, nullptr));
+ result = convertCharArray(path.GetRawBuffer(nullptr));
if (isTestModeEnabled())
result += QLatin1String("/qttest");
break;
diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp
index 1690dd83ee..4c44016fdf 100644
--- a/src/corelib/tools/qlocale_win.cpp
+++ b/src/corelib/tools/qlocale_win.cpp
@@ -663,10 +663,10 @@ QVariant QSystemLocalePrivate::uiLanguages()
unsigned int size;
languageList->get_Size(&size);
for (unsigned int i = 0; i < size; ++i) {
- HSTRING language;
- languageList->GetAt(i, &language);
+ HString language;
+ languageList->GetAt(i, language.GetAddressOf());
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(language, &length);
+ PCWSTR rawString = language.GetRawBuffer(&length);
result << QString::fromWCharArray(rawString, length);
}
#else // !Q_OS_WINPHONE
diff --git a/src/network/kernel/qdnslookup_winrt.cpp b/src/network/kernel/qdnslookup_winrt.cpp
index 6ac944934a..08f3167a29 100644
--- a/src/network/kernel/qdnslookup_winrt.cpp
+++ b/src/network/kernel/qdnslookup_winrt.cpp
@@ -98,9 +98,9 @@ void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestN
GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Sockets_DatagramSocket).Get(), &datagramSocketStatics);
IAsyncOperation<IVectorView<EndpointPair*> *> *op;
- HSTRING proto;
- WindowsCreateString(L"0", 1, &proto);
- datagramSocketStatics->GetEndpointPairsAsync(host, proto, &op);
+ datagramSocketStatics->GetEndpointPairsAsync(host,
+ HString::MakeReference(L"0").Get(),
+ &op);
datagramSocketStatics->Release();
host->Release();
@@ -134,11 +134,11 @@ void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestN
|| (type == HostNameType_Ipv6 && requestType == QDnsLookup::A))))
continue;
- HSTRING name;
- remoteHost->get_CanonicalName(&name);
+ HString name;
+ remoteHost->get_CanonicalName(name.GetAddressOf());
remoteHost->Release();
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(name, &length);
+ PCWSTR rawString = name.GetRawBuffer(&length);
QDnsHostAddressRecord record;
record.d->name = aceHostname;
record.d->value = QHostAddress(QString::fromWCharArray(rawString, length));
diff --git a/src/network/kernel/qhostinfo_winrt.cpp b/src/network/kernel/qhostinfo_winrt.cpp
index 92897f563d..e02cd98e08 100644
--- a/src/network/kernel/qhostinfo_winrt.cpp
+++ b/src/network/kernel/qhostinfo_winrt.cpp
@@ -95,9 +95,9 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Sockets_DatagramSocket).Get(), &datagramSocketStatics);
IAsyncOperation<IVectorView<EndpointPair*> *> *op;
- HSTRING proto;
- WindowsCreateString(L"0", 1, &proto);
- datagramSocketStatics->GetEndpointPairsAsync(host, proto, &op);
+ datagramSocketStatics->GetEndpointPairsAsync(host,
+ HString::MakeReference(L"0").Get(),
+ &op);
datagramSocketStatics->Release();
host->Release();
@@ -131,11 +131,11 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
if (type == HostNameType_DomainName)
continue;
- HSTRING name;
- remoteHost->get_CanonicalName(&name);
+ HString name;
+ remoteHost->get_CanonicalName(name.GetAddressOf());
remoteHost->Release();
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(name, &length);
+ PCWSTR rawString = name.GetRawBuffer(&length);
QHostAddress addr;
addr.setAddress(QString::fromWCharArray(rawString, length));
if (!addresses.contains(addr))
@@ -170,22 +170,22 @@ QString QHostInfo::localHostName()
if (type != HostNameType_DomainName)
continue;
- HSTRING name;
- hostName->get_CanonicalName(&name);
+ HString name;
+ hostName->get_CanonicalName(name.GetAddressOf());
hostName->Release();
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(name, &length);
+ PCWSTR rawString = name.GetRawBuffer(&length);
return QString::fromWCharArray(rawString, length);
}
IHostName *firstHost;
hostNames->GetAt(0, &firstHost);
hostNames->Release();
- HSTRING name;
- firstHost->get_CanonicalName(&name);
+ HString name;
+ firstHost->get_CanonicalName(name.GetAddressOf());
firstHost->Release();
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(name, &length);
+ PCWSTR rawString = name.GetRawBuffer(&length);
return QString::fromWCharArray(rawString, length);
}
diff --git a/src/network/kernel/qnetworkinterface_winrt.cpp b/src/network/kernel/qnetworkinterface_winrt.cpp
index 6a814c85d4..48a96928a8 100644
--- a/src/network/kernel/qnetworkinterface_winrt.cpp
+++ b/src/network/kernel/qnetworkinterface_winrt.cpp
@@ -114,11 +114,11 @@ static QList<QNetworkInterfacePrivate *> interfaceListing()
|| (type == HostNameType_Ipv6 && hostInfo.prefixLength > 128))
continue;
- HSTRING name;
- hostName->get_CanonicalName(&name);
+ HString name;
+ hostName->get_CanonicalName(name.GetAddressOf());
hostName->Release();
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(name, &length);
+ PCWSTR rawString = name.GetRawBuffer(&length);
hostInfo.address = QString::fromWCharArray(rawString, length);
hostList << hostInfo;
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index a32a757191..8eb632ff63 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -124,10 +124,10 @@ struct SocketHandler
Q_GLOBAL_STATIC(SocketHandler, gSocketHandler)
-QString qt_QStringFromHSTRING(HSTRING string)
+static inline QString qt_QStringFromHString(const HString &string)
{
UINT32 length;
- PCWSTR rawString = WindowsGetStringRawBuffer(string, &length);
+ PCWSTR rawString = string.GetRawBuffer(&length);
return QString::fromWCharArray(rawString, length);
}
@@ -604,13 +604,13 @@ qint64 QNativeSocketEngine::readDatagram(char *data, qint64 maxlen, QHostAddress
for (int i = 0; i < d->pendingDatagrams.size(); ++i) {
IDatagramSocketMessageReceivedEventArgs *arg = d->pendingDatagrams.at(i);
ComPtr<IHostName> remoteHost;
- HSTRING remoteHostString;
- HSTRING remotePort;
+ HString remoteHostString;
+ HString remotePort;
arg->get_RemoteAddress(&remoteHost);
- arg->get_RemotePort(&remotePort);
- remoteHost->get_CanonicalName(&remoteHostString);
- returnAddress.setAddress(qt_QStringFromHSTRING(remoteHostString));
- returnPort = qt_QStringFromHSTRING(remotePort).toInt();
+ arg->get_RemotePort(remotePort.GetAddressOf());
+ remoteHost->get_CanonicalName(remoteHostString.GetAddressOf());
+ returnAddress.setAddress(qt_QStringFromHString(remoteHostString));
+ returnPort = qt_QStringFromHString(remotePort).toInt();
ComPtr<IDataReader> reader;
arg->GetDataReader(&reader);
if (!reader)
@@ -1097,7 +1097,7 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
if (socketType == QAbstractSocket::TcpSocket) {
ComPtr<IHostName> hostName;
- HSTRING tmpHString;
+ HString tmpHString;
ComPtr<IStreamSocketInformation> info;
if (FAILED(tcp->get_Information(&info))) {
qWarning("QNativeSocketEnginePrivate::fetchConnectionParameters: Could not obtain socket info");
@@ -1105,28 +1105,28 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
info->get_LocalAddress(&hostName);
if (hostName) {
- hostName->get_CanonicalName(&tmpHString);
- localAddress.setAddress(qt_QStringFromHSTRING(tmpHString));
- info->get_LocalPort(&tmpHString);
- localPort = qt_QStringFromHSTRING(tmpHString).toInt();
+ hostName->get_CanonicalName(tmpHString.GetAddressOf());
+ localAddress.setAddress(qt_QStringFromHString(tmpHString));
+ info->get_LocalPort(tmpHString.GetAddressOf());
+ localPort = qt_QStringFromHString(tmpHString).toInt();
}
if (!localPort && tcpListener) {
ComPtr<IStreamSocketListenerInformation> listenerInfo = 0;
tcpListener->get_Information(&listenerInfo);
- listenerInfo->get_LocalPort(&tmpHString);
- localPort = qt_QStringFromHSTRING(tmpHString).toInt();
+ listenerInfo->get_LocalPort(tmpHString.GetAddressOf());
+ localPort = qt_QStringFromHString(tmpHString).toInt();
localAddress == QHostAddress::Any;
}
info->get_RemoteAddress(&hostName);
if (hostName) {
- hostName->get_CanonicalName(&tmpHString);
- peerAddress.setAddress(qt_QStringFromHSTRING(tmpHString));
- info->get_RemotePort(&tmpHString);
- peerPort = qt_QStringFromHSTRING(tmpHString).toInt();
+ hostName->get_CanonicalName(tmpHString.GetAddressOf());
+ peerAddress.setAddress(qt_QStringFromHString(tmpHString));
+ info->get_RemotePort(tmpHString.GetAddressOf());
+ peerPort = qt_QStringFromHString(tmpHString).toInt();
}
} else if (socketType == QAbstractSocket::UdpSocket) {
ComPtr<IHostName> hostName;
- HSTRING tmpHString;
+ HString tmpHString;
ComPtr<IDatagramSocketInformation> info;
if (FAILED(udp->get_Information(&info))) {
qWarning("QNativeSocketEnginePrivate::fetchConnectionParameters: Could not obtain socket information");
@@ -1134,18 +1134,18 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
info->get_LocalAddress(&hostName);
if (hostName) {
- hostName->get_CanonicalName(&tmpHString);
- localAddress.setAddress(qt_QStringFromHSTRING(tmpHString));
- info->get_LocalPort(&tmpHString);
- localPort = qt_QStringFromHSTRING(tmpHString).toInt();
+ hostName->get_CanonicalName(tmpHString.GetAddressOf());
+ localAddress.setAddress(qt_QStringFromHString(tmpHString));
+ info->get_LocalPort(tmpHString.GetAddressOf());
+ localPort = qt_QStringFromHString(tmpHString).toInt();
}
info->get_RemoteAddress(&hostName);
if (hostName) {
- hostName->get_CanonicalName(&tmpHString);
- peerAddress.setAddress(qt_QStringFromHSTRING(tmpHString));
- info->get_RemotePort(&tmpHString);
- peerPort = qt_QStringFromHSTRING(tmpHString).toInt();
+ hostName->get_CanonicalName(tmpHString.GetAddressOf());
+ peerAddress.setAddress(qt_QStringFromHString(tmpHString));
+ info->get_RemotePort(tmpHString.GetAddressOf());
+ peerPort = qt_QStringFromHString(tmpHString).toInt();
}
}
return true;
diff --git a/src/plugins/platforms/winrt/qwinrtplatformmessagedialoghelper.cpp b/src/plugins/platforms/winrt/qwinrtplatformmessagedialoghelper.cpp
index e70d06860c..c2f884055d 100644
--- a/src/plugins/platforms/winrt/qwinrtplatformmessagedialoghelper.cpp
+++ b/src/plugins/platforms/winrt/qwinrtplatformmessagedialoghelper.cpp
@@ -171,10 +171,11 @@ void QWinRTPlatformMessageDialogHelper::hide()
HRESULT QWinRTPlatformMessageDialogHelper::onInvoked(ABI::Windows::UI::Popups::IUICommand *command)
{
- HSTRING hLabel;
+ HString hLabel;
UINT32 labelLength;
- command->get_Label(&hLabel);
- QString label = QString::fromWCharArray(::WindowsGetStringRawBuffer(hLabel, &labelLength));
+ command->get_Label(hLabel.GetAddressOf());
+ PCWSTR rawString = hLabel.GetRawBuffer(&labelLength);
+ QString label = QString::fromWCharArray(rawString, labelLength);
int buttonId = -1;
for (int i = QPlatformDialogHelper::FirstButton; i < QPlatformDialogHelper::LastButton; i<<=1) {
if ( options()->standardButtons() & i ) {
diff --git a/src/plugins/platforms/winrt/qwinrtservices.cpp b/src/plugins/platforms/winrt/qwinrtservices.cpp
index 73c090351b..b0f9247d36 100644
--- a/src/plugins/platforms/winrt/qwinrtservices.cpp
+++ b/src/plugins/platforms/winrt/qwinrtservices.cpp
@@ -81,9 +81,11 @@ bool QWinRTServices::openUrl(const QUrl &url)
return QPlatformServices::openUrl(url);
IUriRuntimeClass *uri;
- QString urlString = url.toString(); HSTRING uriString; HSTRING_HEADER header;
- WindowsCreateStringReference((const wchar_t*)urlString.utf16(), urlString.length(), &header, &uriString);
- m_uriFactory->CreateUri(uriString, &uri);
+ QString urlString = url.toString();
+ // ### TODO: Replace with HStringReference when WP8.0 support is removed
+ HString uriString;
+ uriString.Set((const wchar_t*)urlString.utf16(), urlString.length());
+ m_uriFactory->CreateUri(uriString.Get(), &uri);
if (!uri)
return false;
@@ -107,10 +109,11 @@ bool QWinRTServices::openDocument(const QUrl &url)
return QPlatformServices::openDocument(url);
const QString pathString = QDir::toNativeSeparators(url.toLocalFile());
- HSTRING_HEADER header; HSTRING path;
- WindowsCreateStringReference((const wchar_t*)pathString.utf16(), pathString.length(), &header, &path);
+ // ### TODO: Replace with HStringReference when WP8.0 support is removed
+ HString path;
+ path.Set((const wchar_t*)pathString.utf16(), pathString.length());
IAsyncOperation<StorageFile*> *fileOp;
- m_fileFactory->GetFileFromPathAsync(path, &fileOp);
+ m_fileFactory->GetFileFromPathAsync(path.Get(), &fileOp);
if (!fileOp)
return false;
diff --git a/src/winmain/qtmain_winrt.cpp b/src/winmain/qtmain_winrt.cpp
index eef23130f9..bcb3445bcd 100644
--- a/src/winmain/qtmain_winrt.cpp
+++ b/src/winmain/qtmain_winrt.cpp
@@ -74,6 +74,7 @@ extern "C" {
using namespace ABI::Windows::ApplicationModel;
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
#define qHString(x) Wrappers::HString::MakeReference(x).Get()
#define CoreApplicationClass RuntimeClass_Windows_ApplicationModel_Core_CoreApplication
@@ -186,11 +187,11 @@ private:
for (int i = m_argc; i < m_argv.size(); ++i)
delete[] m_argv[i];
m_argv.resize(m_argc);
- HSTRING arguments;
- launchArgs->get_Arguments(&arguments);
- if (arguments) {
+ HString arguments;
+ launchArgs->get_Arguments(arguments.GetAddressOf());
+ if (arguments.IsValid()) {
foreach (const QByteArray &arg, QString::fromWCharArray(
- WindowsGetStringRawBuffer(arguments, nullptr)).toLocal8Bit().split(' ')) {
+ arguments.GetRawBuffer(nullptr)).toLocal8Bit().split(' ')) {
m_argv.append(qstrdup(arg.constData()));
}
}