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>
This commit is contained in:
Maurice Kalinowski 2014-05-23 17:16:54 +02:00 committed by The Qt Project
parent 69e2d3b3e9
commit 6b9a9a01e2
11 changed files with 82 additions and 77 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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;

View File

@ -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

View File

@ -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));

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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 ) {

View File

@ -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;

View File

@ -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()));
}
}