From 190c76f685f1dcafbcc762082edcdccdb9bb8b0b Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 16 Dec 2015 15:33:42 +0100 Subject: winrt: Use winsock2 API for hostname resolution on WinRT/WinPhone That API has been available for WinRT and Windows Phone for some time now. By using it to get the machine name and for hostname resolution we can get rid of some winrt-only code and use qhostinfo_win.cpp on WinRT and Windows phone as well. Additionally the required capability was added to tst_qhostinfo so that this auto test can be run without any manual editing. Change-Id: I63fa5521bf8cdb0c919bd5a0100ea977c865622a Reviewed-by: Maurice Kalinowski --- src/corelib/global/qglobal.cpp | 54 ++---------------------------------------- src/corelib/global/qglobal.h | 1 - 2 files changed, 2 insertions(+), 53 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 81925642f8..e8c50dff2b 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -66,18 +66,8 @@ #endif #ifdef Q_OS_WINRT -#include -#include -#include -#include -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::Networking; -using namespace ABI::Windows::Networking::Connectivity; -using namespace ABI::Windows::Networking::Sockets; -#endif +#include +#endif // Q_OS_WINRT #if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL) # include @@ -1880,8 +1870,6 @@ QT_BEGIN_INCLUDE_NAMESPACE #include "qt_windows.h" QT_END_INCLUDE_NAMESPACE -#ifndef Q_OS_WINRT - # ifndef QT_BOOTSTRAPPED class QWindowsSockInit { @@ -1912,8 +1900,6 @@ QWindowsSockInit::~QWindowsSockInit() Q_GLOBAL_STATIC(QWindowsSockInit, winsockInit) # endif // QT_BOOTSTRAPPED -#endif // !Q_OS_WINRT - #ifdef Q_OS_WINRT static inline HMODULE moduleHandleForFunction(LPCVOID address) { @@ -2797,42 +2783,6 @@ QString QSysInfo::machineHostName() struct utsname u; if (uname(&u) == 0) return QString::fromLocal8Bit(u.nodename); -#elif defined(Q_OS_WINRT) - ComPtr statics; - GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Connectivity_NetworkInformation).Get(), &statics); - - ComPtr> hostNames; - statics->GetHostNames(&hostNames); - if (!hostNames) - return QString(); - - unsigned int size; - hostNames->get_Size(&size); - if (size == 0) - return QString(); - - for (unsigned int i = 0; i < size; ++i) { - ComPtr hostName; - hostNames->GetAt(i, &hostName); - HostNameType type; - hostName->get_Type(&type); - if (type != HostNameType_DomainName) - continue; - - HString name; - hostName->get_CanonicalName(name.GetAddressOf()); - UINT32 length; - PCWSTR rawString = name.GetRawBuffer(&length); - return QString::fromWCharArray(rawString, length); - } - ComPtr firstHost; - hostNames->GetAt(0, &firstHost); - - HString name; - firstHost->get_CanonicalName(name.GetAddressOf()); - UINT32 length; - PCWSTR rawString = name.GetRawBuffer(&length); - return QString::fromWCharArray(rawString, length); #else # ifdef Q_OS_WIN // Important: QtNetwork depends on machineHostName() initializing ws2_32.dll diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 07a0b5e27a..2551dcb5d3 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -611,7 +611,6 @@ class QDataStream; #if defined(Q_OS_WINRT) # define QT_NO_FILESYSTEMWATCHER -# define QT_NO_GETADDRINFO # define QT_NO_NETWORKPROXY # define QT_NO_PROCESS # define QT_NO_SOCKETNOTIFIER -- cgit v1.2.3