diff options
author | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2015-12-16 15:33:42 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2016-01-05 08:14:31 +0000 |
commit | 190c76f685f1dcafbcc762082edcdccdb9bb8b0b (patch) | |
tree | 6d7d0bdb92da83f8875db96948ae2c80fcb0cd07 /src/corelib/global | |
parent | 2ca20724dd17df96143be160505f982ab6cf4378 (diff) |
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 <maurice.kalinowski@theqtcompany.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 54 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 1 |
2 files changed, 2 insertions, 53 deletions
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 <wrl.h> -#include <windows.networking.h> -#include <windows.networking.sockets.h> -#include <windows.networking.connectivity.h> -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 <Ws2tcpip.h> +#endif // Q_OS_WINRT #if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL) # include <envLib.h> @@ -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<INetworkInformationStatics> statics; - GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Connectivity_NetworkInformation).Get(), &statics); - - ComPtr<IVectorView<HostName *>> 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<IHostName> 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<IHostName> 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 |