X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2690830ea0c100902aa85eb98a56506a5a98ce0d..2cc78389312dce6285d0d6b6e891d24372252ada:/src/msw/dialup.cpp?ds=sidebyside diff --git a/src/msw/dialup.cpp b/src/msw/dialup.cpp index 409b762930..5d94d8d8df 100644 --- a/src/msw/dialup.cpp +++ b/src/msw/dialup.cpp @@ -34,18 +34,46 @@ #ifndef WX_PRECOMP #include "wx/log.h" + #include "wx/intl.h" + #include "wx/event.h" +#endif + +#include "wx/timer.h" +#include "wx/app.h" +#include "wx/generic/choicdgg.h" + +#include "wx/msw/private.h" // must be before #include "dynlib.h" + +#if !wxUSE_DYNLIB_CLASS + #error You need wxUSE_DYNLIB_CLASS to be 1 to compile dialup.cpp. #endif #include "wx/dynlib.h" #include "wx/dialup.h" +DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED) +DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED) + +// Doesn't yet compile under VC++ 4, BC++, Watcom C++: no wininet.h +#if !defined(__BORLANDC__) && \ + (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION(0, 5)) && \ + !defined(__GNUWIN32_OLD__) && \ + !defined(__WATCOMC__) && \ + (!defined(__VISUALC__) || (__VISUALC__ >= 1020)) + #include #include #include -#include "wx/msw/private.h" +// Not in VC++ 5 +#ifndef INTERNET_CONNECTION_LAN +#define INTERNET_CONNECTION_LAN 2 +#endif +#ifndef INTERNET_CONNECTION_PROXY +#define INTERNET_CONNECTION_PROXY 4 +#endif // ---------------------------------------------------------------------------- // constants @@ -85,7 +113,7 @@ typedef DWORD (APIENTRY * RASVALIDATEENTRYNAME)( LPCSTR, LPCSTR ); typedef DWORD (APIENTRY * RASCONNECTIONNOTIFICATION)( HRASCONN, HANDLE, DWORD ); - static const char gs_funcSuffix = 'A'; + static const wxChar gs_funcSuffix = _T('A'); #else // Unicode typedef DWORD (APIENTRY * RASDIAL)( LPRASDIALEXTENSIONS, LPCWSTR, LPRASDIALPARAMSW, DWORD, LPVOID, LPHRASCONN ); typedef DWORD (APIENTRY * RASENUMCONNECTIONS)( LPRASCONNW, LPDWORD, LPDWORD ); @@ -107,11 +135,11 @@ typedef DWORD (APIENTRY * RASVALIDATEENTRYNAME)( LPCWSTR, LPCWSTR ); typedef DWORD (APIENTRY * RASCONNECTIONNOTIFICATION)( HRASCONN, HANDLE, DWORD ); - static const char gs_funcSuffix = 'W'; + static const wxChar gs_funcSuffix = _T('W'); #endif // ASCII/Unicode // structure passed to the secondary thread -struct wxRasThreadData +struct WXDLLEXPORT wxRasThreadData { wxRasThreadData() { @@ -182,7 +210,7 @@ private: void CleanUpThreadData(); // timer used for polling RAS status - class RasTimer : public wxTimer + class WXDLLEXPORT RasTimer : public wxTimer { public: RasTimer(wxDialUpManagerMSW *dialUpManager) @@ -330,9 +358,7 @@ wxDialUpManagerMSW::wxDialUpManagerMSW() ms_dllRas = wxDllLoader::LoadLibrary("RASAPI32"); if ( !ms_dllRas ) { - wxLogError(_("Dial up functions are unavailable because the " - "remote access service (RAS) is not installed " - "on this machine. Please install it.")); + wxLogError(_("Dial up functions are unavailable because the remote access service (RAS) is not installed on this machine. Please install it.")); } else { @@ -392,10 +418,12 @@ wxDialUpManagerMSW::wxDialUpManagerMSW() exit: if ( funcName ) { - wxLogError(_("The version of remote access service (RAS) " - "installed on this machine is too old, please " - "upgrade (the following required function is " - "missing: %s)."), funcName); + static const wxChar *msg = wxTRANSLATE( +"The version of remote access service (RAS) installed on this machine is too\ +old, please upgrade (the following required function is missing: %s)." + ); + + wxLogError(wxGetTranslation(msg), funcName); wxDllLoader::UnloadLibrary(ms_dllRas); ms_dllRas = 0; @@ -438,8 +466,8 @@ wxString wxDialUpManagerMSW::GetErrorString(DWORD error) default: { - wxLogSysError(dwRet, _("Failed to retrieve text of RAS " - "error message")); + wxLogSysError(dwRet, + _("Failed to retrieve text of RAS error message")); wxString msg; msg.Printf(_("unknown error (error code %08x)."), error); @@ -495,7 +523,7 @@ HRASCONN wxDialUpManagerMSW::FindActiveConnection() { // an error occured wxLogError(_("Cannot find active dialup connection: %s"), - GetErrorString(dwRet)); + GetErrorString(dwRet).c_str()); return 0; } } @@ -515,8 +543,7 @@ HRASCONN wxDialUpManagerMSW::FindActiveConnection() // connection) - the warning is really needed because this function // is used, for example, to select the connection to hang up and so // we may hang up the wrong connection here... - wxLogWarning(_("Several active dialup connections found, " - "choosing one randomly.")); + wxLogWarning(_("Several active dialup connections found, choosing one randomly.")); // fall through case 1: @@ -535,7 +562,7 @@ void wxDialUpManagerMSW::CleanUpThreadData() { if ( !SetEvent(m_data.hEventQuit) ) { - wxLogLastError("SetEvent(RasThreadQuit)"); + wxLogLastError(_T("SetEvent(RasThreadQuit)")); } CloseHandle(m_hThread); @@ -617,7 +644,7 @@ void wxDialUpManagerMSW::OnDialProgress(RASCONNSTATE rasconnstate, if ( dwError ) { wxLogError(_("Failed to establish dialup connection: %s"), - GetErrorString(dwError)); + GetErrorString(dwError).c_str()); // we should still call RasHangUp() if we got a non 0 connection if ( ms_hRasConnection ) @@ -676,7 +703,8 @@ size_t wxDialUpManagerMSW::GetISPNames(wxArrayString& names) const else if ( dwRet != 0 ) { // some other error - abort - wxLogError(_("Failed to get ISP names: %s"), GetErrorString(dwRet)); + wxLogError(_("Failed to get ISP names: %s"), + GetErrorString(dwRet).c_str()); free(rasEntries); @@ -704,11 +732,11 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP, bool async) { // check preconditions - wxCHECK_MSG( IsOk(), FALSE, T("using uninitialized wxDialUpManager") ); + wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") ); if ( ms_hRasConnection ) { - wxFAIL_MSG(T("there is already an active connection")); + wxFAIL_MSG(wxT("there is already an active connection")); return TRUE; } @@ -744,8 +772,7 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP, entryName = wxGetSingleChoice ( _("Choose ISP to dial"), - _("Please choose which ISP do you want to " - "connect to"), + _("Please choose which ISP do you want to connect to"), count, strings ); @@ -763,7 +790,7 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP, RASDIALPARAMS rasDialParams; rasDialParams.dwSize = sizeof(rasDialParams); - strncpy(rasDialParams.szEntryName, entryName, RAS_MaxEntryName); + wxStrncpy(rasDialParams.szEntryName, entryName, RAS_MaxEntryName); // do we have the username and password? if ( !username || !password ) @@ -785,8 +812,8 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP, } else { - strncpy(rasDialParams.szUserName, username, UNLEN); - strncpy(rasDialParams.szPassword, password, PWLEN); + wxStrncpy(rasDialParams.szUserName, username, UNLEN); + wxStrncpy(rasDialParams.szPassword, password, PWLEN); } // default values for other fields @@ -838,8 +865,8 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP, if ( dwRet != 0 ) { wxLogError(_("Failed to %s dialup connection: %s"), - async ? _("initiate") : _("establish"), - GetErrorString(dwRet)); + wxString(async ? _("initiate") : _("establish")).c_str(), + GetErrorString(dwRet).c_str()); // we should still call RasHangUp() if we got a non 0 connection if ( ms_hRasConnection ) @@ -875,7 +902,7 @@ bool wxDialUpManagerMSW::CancelDialing() return FALSE; } - wxASSERT_MSG( ms_hRasConnection, T("dialing but no connection?") ); + wxASSERT_MSG( ms_hRasConnection, wxT("dialing but no connection?") ); ms_dialer = NULL; @@ -884,7 +911,7 @@ bool wxDialUpManagerMSW::CancelDialing() bool wxDialUpManagerMSW::HangUp() { - wxCHECK_MSG( IsOk(), FALSE, T("using uninitialized wxDialUpManager") ); + wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") ); // we may terminate either the connection we initiated or another one which // is active now @@ -911,7 +938,7 @@ bool wxDialUpManagerMSW::HangUp() if ( dwRet != 0 ) { wxLogError(_("Failed to terminate the dialup connection: %s"), - GetErrorString(dwRet)); + GetErrorString(dwRet).c_str()); } ms_isConnected = FALSE; @@ -949,9 +976,6 @@ bool wxDialUpManagerMSW::IsAlwaysOnline() const // there is some connection to the net, see of which type ms_isAlwaysOnline = (flags & INTERNET_CONNECTION_LAN != 0) || (flags & INTERNET_CONNECTION_PROXY != 0); - - wxLogMessage("InternetGetConnectedState() returned TRUE, " - "flags = %08x", flags); } else { @@ -982,14 +1006,14 @@ bool wxDialUpManagerMSW::IsAlwaysOnline() const } } - wxASSERT_MSG( ms_isAlwaysOnline != -1, T("logic error") ); + wxASSERT_MSG( ms_isAlwaysOnline != -1, wxT("logic error") ); return ms_isAlwaysOnline != 0; } bool wxDialUpManagerMSW::IsOnline() const { - wxCHECK_MSG( IsOk(), FALSE, T("using uninitialized wxDialUpManager") ); + wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") ); if ( ms_userSpecifiedOnlineStatus != -1 ) { @@ -1005,14 +1029,14 @@ bool wxDialUpManagerMSW::IsOnline() const void wxDialUpManagerMSW::SetOnlineStatus(bool isOnline) { - wxCHECK_RET( IsOk(), T("using uninitialized wxDialUpManager") ); + wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") ); ms_userSpecifiedOnlineStatus = isOnline; } bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) { - wxCHECK_MSG( IsOk(), FALSE, T("using uninitialized wxDialUpManager") ); + wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") ); bool ok = ms_pfnRasConnectionNotification != 0; @@ -1030,7 +1054,7 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) dwSuspendCount = ResumeThread(m_hThread); if ( dwSuspendCount == (DWORD)-1 ) { - wxLogLastError("ResumeThread(RasThread)"); + wxLogLastError(wxT("ResumeThread(RasThread)")); ok = FALSE; } @@ -1058,7 +1082,7 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) ); if ( !m_data.hEventRas ) { - wxLogLastError("CreateEvent(RasStatus)"); + wxLogLastError(wxT("CreateEvent(RasStatus)")); ok = FALSE; } @@ -1070,7 +1094,7 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) m_data.hEventQuit = CreateEvent(NULL, FALSE, FALSE, NULL); if ( !m_data.hEventQuit ) { - wxLogLastError("CreateEvent(RasThreadQuit)"); + wxLogLastError(wxT("CreateEvent(RasThreadQuit)")); CleanUpThreadData(); @@ -1082,14 +1106,14 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) { // create a hidden window to receive notification about connections // status change - extern wxChar wxPanelClassName[]; + extern const wxChar *wxPanelClassName; ms_hwndRas = ::CreateWindow(wxPanelClassName, NULL, 0, 0, 0, 0, 0, NULL, (HMENU)NULL, wxGetInstance(), 0); if ( !ms_hwndRas ) { - wxLogLastError("CreateWindow(RasHiddenWindow)"); + wxLogLastError(wxT("CreateWindow(RasHiddenWindow)")); CleanUpThreadData(); @@ -1126,7 +1150,7 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) if ( !m_hThread ) { - wxLogLastError("CreateThread(RasStatusThread)"); + wxLogLastError(wxT("CreateThread(RasStatusThread)")); CleanUpThreadData(); } @@ -1144,8 +1168,8 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) if ( dwRet != 0 ) { - wxLogDebug(T("RasConnectionNotification() failed: %s"), - GetErrorString(dwRet)); + wxLogDebug(wxT("RasConnectionNotification() failed: %s"), + GetErrorString(dwRet).c_str()); CleanUpThreadData(); } @@ -1170,14 +1194,14 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus() { - wxCHECK_RET( IsOk(), T("using uninitialized wxDialUpManager") ); + wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") ); if ( m_hThread ) { // we have running secondary thread, it's just enough to suspend it if ( SuspendThread(m_hThread) == (DWORD)-1 ) { - wxLogLastError("SuspendThread(RasThread)"); + wxLogLastError(wxT("SuspendThread(RasThread)")); } } else @@ -1194,7 +1218,7 @@ void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus() void wxDialUpManagerMSW::SetWellKnownHost(const wxString& WXUNUSED(hostname), int WXUNUSED(port)) { - wxCHECK_RET( IsOk(), T("using uninitialized wxDialUpManager") ); + wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") ); // nothing to do - we don't use this } @@ -1202,7 +1226,7 @@ void wxDialUpManagerMSW::SetWellKnownHost(const wxString& WXUNUSED(hostname), void wxDialUpManagerMSW::SetConnectCommand(const wxString& WXUNUSED(dial), const wxString& WXUNUSED(hangup)) { - wxCHECK_RET( IsOk(), T("using uninitialized wxDialUpManager") ); + wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") ); // nothing to do - we don't use this } @@ -1235,7 +1259,7 @@ static DWORD wxRasMonitorThread(wxRasThreadData *data) break; case WAIT_FAILED: - wxLogLastError("WaitForMultipleObjects(RasMonitor)"); + wxLogLastError(wxT("WaitForMultipleObjects(RasMonitor)")); break; } } @@ -1267,10 +1291,12 @@ static void WINAPI wxRasDialFunc(UINT unMsg, { wxDialUpManagerMSW *dialUpManager = wxDialUpManagerMSW::GetDialer(); - wxCHECK_RET( dialUpManager, T("who started to dial then?") ); + wxCHECK_RET( dialUpManager, wxT("who started to dial then?") ); SendMessage(dialUpManager->GetRasWindow(), wxWM_RAS_DIALING_PROGRESS, rasconnstate, dwError); } +#endif + // __BORLANDC__ #endif // wxUSE_DIALUP_MANAGER