+
+WXDLLIMPEXP_DATA_BASE(const wxChar *) wxUserResourceStr = wxT("TEXT");
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// get host name and related
+// ----------------------------------------------------------------------------
+
+// Get hostname only (without domain name)
+bool wxGetHostName(wxChar *buf, int maxSize)
+{
+#if defined(__WXWINCE__)
+ // GetComputerName() is not supported but the name seems to be stored in
+ // this location in the registry, at least for PPC2003 and WM5
+ wxString hostName;
+ wxRegKey regKey(wxRegKey::HKLM, wxT("Ident"));
+ if ( !regKey.HasValue(wxT("Name")) ||
+ !regKey.QueryValue(wxT("Name"), hostName) )
+ return false;
+
+ wxStrlcpy(buf, hostName.t_str(), maxSize);
+#else // !__WXWINCE__
+ DWORD nSize = maxSize;
+ if ( !::GetComputerName(buf, &nSize) )
+ {
+ wxLogLastError(wxT("GetComputerName"));
+
+ return false;
+ }
+#endif // __WXWINCE__/!__WXWINCE__
+
+ return true;
+}
+
+// get full hostname (with domain name if possible)
+bool wxGetFullHostName(wxChar *buf, int maxSize)
+{
+#if !defined( __WXMICROWIN__) && wxUSE_DYNLIB_CLASS && wxUSE_SOCKETS
+ // TODO should use GetComputerNameEx() when available
+
+ // we don't want to always link with Winsock DLL as we might not use it at
+ // all, so load it dynamically here if needed (and don't complain if it is
+ // missing, we handle this)
+ wxLogNull noLog;
+
+ wxDynamicLibrary dllWinsock(wxT("ws2_32.dll"), wxDL_VERBATIM);
+ if ( dllWinsock.IsLoaded() )
+ {
+ typedef int (PASCAL *WSAStartup_t)(WORD, WSADATA *);
+ typedef int (PASCAL *gethostname_t)(char *, int);
+ typedef hostent* (PASCAL *gethostbyname_t)(const char *);
+ typedef hostent* (PASCAL *gethostbyaddr_t)(const char *, int , int);
+ typedef int (PASCAL *WSACleanup_t)(void);
+
+ #define LOAD_WINSOCK_FUNC(func) \
+ func ## _t \
+ pfn ## func = (func ## _t)dllWinsock.GetSymbol(wxT(#func))
+
+ LOAD_WINSOCK_FUNC(WSAStartup);
+
+ WSADATA wsa;
+ if ( pfnWSAStartup && pfnWSAStartup(MAKEWORD(1, 1), &wsa) == 0 )
+ {
+ LOAD_WINSOCK_FUNC(gethostname);
+
+ wxString host;
+ if ( pfngethostname )
+ {
+ char bufA[256];
+ if ( pfngethostname(bufA, WXSIZEOF(bufA)) == 0 )
+ {
+ // gethostname() won't usually include the DNS domain name,
+ // for this we need to work a bit more
+ if ( !strchr(bufA, '.') )
+ {
+ LOAD_WINSOCK_FUNC(gethostbyname);
+
+ struct hostent *pHostEnt = pfngethostbyname
+ ? pfngethostbyname(bufA)
+ : NULL;
+
+ if ( pHostEnt )
+ {
+ // Windows will use DNS internally now
+ LOAD_WINSOCK_FUNC(gethostbyaddr);
+
+ pHostEnt = pfngethostbyaddr
+ ? pfngethostbyaddr(pHostEnt->h_addr,
+ 4, AF_INET)
+ : NULL;
+ }
+
+ if ( pHostEnt )
+ {
+ host = wxString::FromAscii(pHostEnt->h_name);
+ }
+ }
+ }
+ }
+
+ LOAD_WINSOCK_FUNC(WSACleanup);
+ if ( pfnWSACleanup )
+ pfnWSACleanup();
+
+
+ if ( !host.empty() )
+ {
+ wxStrlcpy(buf, host.c_str(), maxSize);
+
+ return true;
+ }
+ }
+ }
+#endif // !__WXMICROWIN__
+
+ return wxGetHostName(buf, maxSize);