X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bfbd6dc1921a17bd880d580dd660e8bc478a9391..6342bd1ab36c1957684c00d408d09fba65d33db6:/src/msw/utils.cpp?ds=sidebyside diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 7126032d69..14346f1413 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -32,12 +32,24 @@ #include "wx/utils.h" #include "wx/app.h" #include "wx/cursor.h" + #include "wx/intl.h" + #include "wx/log.h" #endif //WX_PRECOMP +// In some mingws there is a missing extern "C" int the winsock header, +// so we put it here just to be safe. Note that this must appear _before_ +// #include "wx/msw/private.h" which itself includes , as this +// one in turn includes unless we define WIN32_LEAN_AND_MEAN. +// +#if defined(__WIN32__) && !defined(__TWIN32__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) +extern "C" { + #include // we use socket functions in wxGetFullHostName() +} +#endif + #include "wx/msw/private.h" // includes #include "wx/timer.h" -#include "wx/intl.h" #include @@ -54,8 +66,6 @@ #include #endif //GNUWIN32 -#include "wx/log.h" - #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs // this (3.1 I believe) and how to test for it. // If this works for Borland 4.0 as well, then no worries. @@ -117,7 +127,7 @@ #endif # if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS -# define new new(__FILE__,__LINE__) +# define new new(__TFILE__,__LINE__) # endif #endif @@ -146,16 +156,14 @@ static const wxChar eUSERID[] = wxT("UserId"); // get host name and related // ---------------------------------------------------------------------------- -// Get full hostname (eg. DoDo.BSn-Germany.crg.de) +// Get hostname only (without domain name) bool wxGetHostName(wxChar *buf, int maxSize) { #if defined(__WIN32__) && !defined(__TWIN32__) - // TODO should use GetComputerNameEx() when available - DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { - wxLogLastError("GetComputerName"); + wxLogLastError(wxT("GetComputerName")); return FALSE; } @@ -174,8 +182,48 @@ bool wxGetHostName(wxChar *buf, int maxSize) #endif } +// get full hostname (with domain name if possible) bool wxGetFullHostName(wxChar *buf, int maxSize) { +#if defined(__WIN32__) && !defined(__TWIN32__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) + // TODO should use GetComputerNameEx() when available + WSADATA wsa; + if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) + { + wxString host; + char bufA[256]; + if ( gethostname(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, '.') ) + { + struct hostent *pHostEnt = gethostbyname(bufA); + + if ( pHostEnt ) + { + // Windows will use DNS internally now + pHostEnt = gethostbyaddr(pHostEnt->h_addr, 4, PF_INET); + } + + if ( pHostEnt ) + { + host = pHostEnt->h_name; + } + } + } + + WSACleanup(); + + if ( !!host ) + { + wxStrncpy(buf, host, maxSize); + + return TRUE; + } + } +#endif // Win32 + return wxGetHostName(buf, maxSize); } @@ -402,7 +450,7 @@ bool wxDirExists(const wxString& dir) if ( h == INVALID_HANDLE_VALUE ) { - wxLogLastError("FindFirstFile"); + wxLogLastError(wxT("FindFirstFile")); return FALSE; } @@ -543,7 +591,7 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) *majorVsn = info.dwMajorVersion; if (minorVsn) *minorVsn = info.dwMinorVersion; - + switch ( info.dwPlatformId ) { case VER_PLATFORM_WIN32s: @@ -862,8 +910,6 @@ bool wxCheckForInterrupt(wxWindow *wnd) return TRUE; } -#endif // wxUSE_GUI - // MSW only: get user-defined resource from the .res file. // Returns NULL or newly-allocated memory, so use delete[] to clean up. @@ -1004,6 +1050,8 @@ WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) #endif // Win16/32 } +#endif // wxUSE_GUI + #if 0 //------------------------------------------------------------------------ // wild character routines @@ -1161,7 +1209,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) return ((*str == '\0') && (*pattern == '\0')); }; -#endif +#endif // 0 #if 0