]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dialup.cpp
wxCocoa: Better icon support
[wxWidgets.git] / src / msw / dialup.cpp
CommitLineData
a0b4c98b
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: msw/dialup.cpp
3// Purpose: MSW implementation of network/dialup classes and functions
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 07.07.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27// these functions require Win32
28#if defined(__WIN16__) && wxUSE_DIALUP_MANAGER
29 #undef wxUSE_DIALUP_MANAGER
30 #define wxUSE_DIALUP_MANAGER 0
31#endif // wxUSE_DIALUP_MANAGER && Win16
32
33#if wxUSE_DIALUP_MANAGER
34
35#ifndef WX_PRECOMP
36 #include "wx/log.h"
d1f4970d
VZ
37 #include "wx/intl.h"
38 #include "wx/event.h"
a0b4c98b
VZ
39#endif
40
fcec6429
VZ
41#include "wx/timer.h"
42#include "wx/app.h"
43#include "wx/generic/choicdgg.h"
44
a0b4c98b 45#include "wx/dynlib.h"
2690830e 46#include "wx/dialup.h"
a0b4c98b 47
2e4df4bf
VZ
48DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
49DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
50
3bce6687
JS
51// Doesn't yet compile under VC++ 4, BC++, Watcom C++,
52// Wine: no wininet.h
3aabb24c 53#if (!defined(__BORLANDC__) || (__BORLANDC__>=0x550)) && \
ce20b5d7 54 (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION(0, 5)) && \
7ba4fbeb
VZ
55 !defined(__GNUWIN32_OLD__) && \
56 !defined(__WATCOMC__) && \
5283098e 57 !defined(__WINE__) && \
7ba4fbeb 58 (!defined(__VISUALC__) || (__VISUALC__ >= 1020))
106f0395 59
a0b4c98b
VZ
60#include <ras.h>
61#include <raserror.h>
62
2690830e
VZ
63#include <wininet.h>
64
a2327a9f
JS
65// Not in VC++ 5
66#ifndef INTERNET_CONNECTION_LAN
67#define INTERNET_CONNECTION_LAN 2
68#endif
69#ifndef INTERNET_CONNECTION_PROXY
70#define INTERNET_CONNECTION_PROXY 4
71#endif
72
a0b4c98b
VZ
73// ----------------------------------------------------------------------------
74// constants
75// ----------------------------------------------------------------------------
76
77// this message is sent by the secondary thread when RAS status changes
78#define wxWM_RAS_STATUS_CHANGED (WM_USER + 10010)
2690830e 79#define wxWM_RAS_DIALING_PROGRESS (WM_USER + 10011)
a0b4c98b
VZ
80
81// ----------------------------------------------------------------------------
82// types
83// ----------------------------------------------------------------------------
84
85// the signatures of RAS functions: all this is quite heavy, but we must do it
86// to allow running wxWin programs on machine which don't have RAS installed
87// (this does exist) - if we link with rasapi32.lib, the program will fail on
88// startup because of the missing DLL...
89
90#ifndef UNICODE
2690830e
VZ
91 typedef DWORD (APIENTRY * RASDIAL)( LPRASDIALEXTENSIONS, LPCSTR, LPRASDIALPARAMSA, DWORD, LPVOID, LPHRASCONN );
92 typedef DWORD (APIENTRY * RASENUMCONNECTIONS)( LPRASCONNA, LPDWORD, LPDWORD );
93 typedef DWORD (APIENTRY * RASENUMENTRIES)( LPCSTR, LPCSTR, LPRASENTRYNAMEA, LPDWORD, LPDWORD );
94 typedef DWORD (APIENTRY * RASGETCONNECTSTATUS)( HRASCONN, LPRASCONNSTATUSA );
95 typedef DWORD (APIENTRY * RASGETERRORSTRING)( UINT, LPSTR, DWORD );
96 typedef DWORD (APIENTRY * RASHANGUP)( HRASCONN );
97 typedef DWORD (APIENTRY * RASGETPROJECTIONINFO)( HRASCONN, RASPROJECTION, LPVOID, LPDWORD );
98 typedef DWORD (APIENTRY * RASCREATEPHONEBOOKENTRY)( HWND, LPCSTR );
99 typedef DWORD (APIENTRY * RASEDITPHONEBOOKENTRY)( HWND, LPCSTR, LPCSTR );
100 typedef DWORD (APIENTRY * RASSETENTRYDIALPARAMS)( LPCSTR, LPRASDIALPARAMSA, BOOL );
101 typedef DWORD (APIENTRY * RASGETENTRYDIALPARAMS)( LPCSTR, LPRASDIALPARAMSA, LPBOOL );
102 typedef DWORD (APIENTRY * RASENUMDEVICES)( LPRASDEVINFOA, LPDWORD, LPDWORD );
103 typedef DWORD (APIENTRY * RASGETCOUNTRYINFO)( LPRASCTRYINFOA, LPDWORD );
104 typedef DWORD (APIENTRY * RASGETENTRYPROPERTIES)( LPCSTR, LPCSTR, LPRASENTRYA, LPDWORD, LPBYTE, LPDWORD );
105 typedef DWORD (APIENTRY * RASSETENTRYPROPERTIES)( LPCSTR, LPCSTR, LPRASENTRYA, DWORD, LPBYTE, DWORD );
106 typedef DWORD (APIENTRY * RASRENAMEENTRY)( LPCSTR, LPCSTR, LPCSTR );
107 typedef DWORD (APIENTRY * RASDELETEENTRY)( LPCSTR, LPCSTR );
108 typedef DWORD (APIENTRY * RASVALIDATEENTRYNAME)( LPCSTR, LPCSTR );
109 typedef DWORD (APIENTRY * RASCONNECTIONNOTIFICATION)( HRASCONN, HANDLE, DWORD );
a0b4c98b 110
f6bcfd97 111 static const wxChar gs_funcSuffix = _T('A');
a0b4c98b 112#else // Unicode
2690830e
VZ
113 typedef DWORD (APIENTRY * RASDIAL)( LPRASDIALEXTENSIONS, LPCWSTR, LPRASDIALPARAMSW, DWORD, LPVOID, LPHRASCONN );
114 typedef DWORD (APIENTRY * RASENUMCONNECTIONS)( LPRASCONNW, LPDWORD, LPDWORD );
115 typedef DWORD (APIENTRY * RASENUMENTRIES)( LPCWSTR, LPCWSTR, LPRASENTRYNAMEW, LPDWORD, LPDWORD );
116 typedef DWORD (APIENTRY * RASGETCONNECTSTATUS)( HRASCONN, LPRASCONNSTATUSW );
117 typedef DWORD (APIENTRY * RASGETERRORSTRING)( UINT, LPWSTR, DWORD );
118 typedef DWORD (APIENTRY * RASHANGUP)( HRASCONN );
119 typedef DWORD (APIENTRY * RASGETPROJECTIONINFO)( HRASCONN, RASPROJECTION, LPVOID, LPDWORD );
120 typedef DWORD (APIENTRY * RASCREATEPHONEBOOKENTRY)( HWND, LPCWSTR );
121 typedef DWORD (APIENTRY * RASEDITPHONEBOOKENTRY)( HWND, LPCWSTR, LPCWSTR );
122 typedef DWORD (APIENTRY * RASSETENTRYDIALPARAMS)( LPCWSTR, LPRASDIALPARAMSW, BOOL );
123 typedef DWORD (APIENTRY * RASGETENTRYDIALPARAMS)( LPCWSTR, LPRASDIALPARAMSW, LPBOOL );
124 typedef DWORD (APIENTRY * RASENUMDEVICES)( LPRASDEVINFOW, LPDWORD, LPDWORD );
125 typedef DWORD (APIENTRY * RASGETCOUNTRYINFO)( LPRASCTRYINFOW, LPDWORD );
126 typedef DWORD (APIENTRY * RASGETENTRYPROPERTIES)( LPCWSTR, LPCWSTR, LPRASENTRYW, LPDWORD, LPBYTE, LPDWORD );
127 typedef DWORD (APIENTRY * RASSETENTRYPROPERTIES)( LPCWSTR, LPCWSTR, LPRASENTRYW, DWORD, LPBYTE, DWORD );
128 typedef DWORD (APIENTRY * RASRENAMEENTRY)( LPCWSTR, LPCWSTR, LPCWSTR );
129 typedef DWORD (APIENTRY * RASDELETEENTRY)( LPCWSTR, LPCWSTR );
130 typedef DWORD (APIENTRY * RASVALIDATEENTRYNAME)( LPCWSTR, LPCWSTR );
131 typedef DWORD (APIENTRY * RASCONNECTIONNOTIFICATION)( HRASCONN, HANDLE, DWORD );
a0b4c98b 132
f6bcfd97 133 static const wxChar gs_funcSuffix = _T('W');
a0b4c98b
VZ
134#endif // ASCII/Unicode
135
136// structure passed to the secondary thread
3b415ba4 137struct WXDLLEXPORT wxRasThreadData
a0b4c98b
VZ
138{
139 wxRasThreadData()
140 {
141 hWnd = 0;
142 hEventRas = hEventQuit = INVALID_HANDLE_VALUE;
143 dialUpManager = NULL;
144 }
145
146 HWND hWnd; // window to send notifications to
147 HANDLE hEventRas, // event which RAS signals when status changes
148 hEventQuit; // event which we signal when we terminate
149
150 class WXDLLEXPORT wxDialUpManagerMSW *dialUpManager; // the owner
151};
152
153// ----------------------------------------------------------------------------
154// wxDialUpManager class for MSW
155// ----------------------------------------------------------------------------
156
157class WXDLLEXPORT wxDialUpManagerMSW : public wxDialUpManager
158{
159public:
160 // ctor & dtor
161 wxDialUpManagerMSW();
162 virtual ~wxDialUpManagerMSW();
163
164 // implement base class pure virtuals
165 virtual bool IsOk() const;
2690830e 166 virtual size_t GetISPNames(wxArrayString& names) const;
a0b4c98b
VZ
167 virtual bool Dial(const wxString& nameOfISP,
168 const wxString& username,
169 const wxString& password,
170 bool async);
171 virtual bool IsDialing() const;
172 virtual bool CancelDialing();
173 virtual bool HangUp();
2690830e 174 virtual bool IsAlwaysOnline() const;
a0b4c98b
VZ
175 virtual bool IsOnline() const;
176 virtual void SetOnlineStatus(bool isOnline = TRUE);
177 virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds);
178 virtual void DisableAutoCheckOnlineStatus();
179 virtual void SetWellKnownHost(const wxString& hostname, int port);
180 virtual void SetConnectCommand(const wxString& commandDial,
181 const wxString& commandHangup);
182
183 // for RasTimer
184 void CheckRasStatus();
185
186 // for wxRasStatusWindowProc
187 void OnConnectStatusChange();
2690830e 188 void OnDialProgress(RASCONNSTATE rasconnstate, DWORD dwError);
a0b4c98b
VZ
189
190 // for wxRasDialFunc
2690830e 191 static HWND GetRasWindow() { return ms_hwndRas; }
a0b4c98b
VZ
192 static wxDialUpManagerMSW *GetDialer() { return ms_dialer; }
193
194private:
195 // return the error string for the given RAS error code
196 static wxString GetErrorString(DWORD error);
197
198 // find the (first) handle of the active connection
199 static HRASCONN FindActiveConnection();
200
201 // notify the application about status change
202 void NotifyApp(bool connected, bool fromOurselves = FALSE) const;
203
204 // destroy the thread data and the thread itself
205 void CleanUpThreadData();
206
207 // timer used for polling RAS status
3b415ba4 208 class WXDLLEXPORT RasTimer : public wxTimer
a0b4c98b
VZ
209 {
210 public:
211 RasTimer(wxDialUpManagerMSW *dialUpManager)
212 { m_dialUpManager = dialUpManager; }
213
214 virtual void Notify() { m_dialUpManager->CheckRasStatus(); }
215
216 private:
217 wxDialUpManagerMSW *m_dialUpManager;
2eb10e2a
VZ
218
219 DECLARE_NO_COPY_CLASS(RasTimer)
a0b4c98b
VZ
220 } m_timerStatusPolling;
221
222 // thread handle for the thread sitting on connection change event
223 HANDLE m_hThread;
224
225 // data used by this thread and our hidden window to send messages between
226 // each other
227 wxRasThreadData m_data;
228
4f89dbc4 229 // the handle of rasapi32.dll when it's loaded
4522bb3e 230 wxDynamicLibrary m_dllRas;
4f89dbc4 231
2690830e
VZ
232 // the hidden window we use for passing messages between threads
233 static HWND ms_hwndRas;
234
a0b4c98b
VZ
235 // the handle of the connection we initiated or 0 if none
236 static HRASCONN ms_hRasConnection;
237
a0b4c98b
VZ
238 // the pointers to RAS functions
239 static RASDIAL ms_pfnRasDial;
240 static RASENUMCONNECTIONS ms_pfnRasEnumConnections;
241 static RASENUMENTRIES ms_pfnRasEnumEntries;
242 static RASGETCONNECTSTATUS ms_pfnRasGetConnectStatus;
243 static RASGETERRORSTRING ms_pfnRasGetErrorString;
244 static RASHANGUP ms_pfnRasHangUp;
245 static RASGETPROJECTIONINFO ms_pfnRasGetProjectionInfo;
246 static RASCREATEPHONEBOOKENTRY ms_pfnRasCreatePhonebookEntry;
247 static RASEDITPHONEBOOKENTRY ms_pfnRasEditPhonebookEntry;
248 static RASSETENTRYDIALPARAMS ms_pfnRasSetEntryDialParams;
249 static RASGETENTRYDIALPARAMS ms_pfnRasGetEntryDialParams;
250 static RASENUMDEVICES ms_pfnRasEnumDevices;
251 static RASGETCOUNTRYINFO ms_pfnRasGetCountryInfo;
252 static RASGETENTRYPROPERTIES ms_pfnRasGetEntryProperties;
253 static RASSETENTRYPROPERTIES ms_pfnRasSetEntryProperties;
254 static RASRENAMEENTRY ms_pfnRasRenameEntry;
255 static RASDELETEENTRY ms_pfnRasDeleteEntry;
256 static RASVALIDATEENTRYNAME ms_pfnRasValidateEntryName;
257
258 // this function is not supported by Win95
259 static RASCONNECTIONNOTIFICATION ms_pfnRasConnectionNotification;
260
261 // if this flag is different from -1, it overrides IsOnline()
262 static int ms_userSpecifiedOnlineStatus;
263
264 // this flag tells us if we're online
265 static int ms_isConnected;
266
267 // this flag tells us whether a call to RasDial() is in progress
268 static wxDialUpManagerMSW *ms_dialer;
2eb10e2a
VZ
269
270 DECLARE_NO_COPY_CLASS(wxDialUpManagerMSW)
a0b4c98b
VZ
271};
272
273// ----------------------------------------------------------------------------
274// private functions
275// ----------------------------------------------------------------------------
276
277static LRESULT WINAPI wxRasStatusWindowProc(HWND hWnd, UINT message,
278 WPARAM wParam, LPARAM lParam);
279
280static DWORD wxRasMonitorThread(wxRasThreadData *data);
281
282static void WINAPI wxRasDialFunc(UINT unMsg,
283 RASCONNSTATE rasconnstate,
284 DWORD dwError);
285
286// ============================================================================
287// implementation
288// ============================================================================
289
290// ----------------------------------------------------------------------------
291// init the static variables
292// ----------------------------------------------------------------------------
293
294HRASCONN wxDialUpManagerMSW::ms_hRasConnection = 0;
295
2690830e
VZ
296HWND wxDialUpManagerMSW::ms_hwndRas = 0;
297
a0b4c98b
VZ
298RASDIAL wxDialUpManagerMSW::ms_pfnRasDial = 0;
299RASENUMCONNECTIONS wxDialUpManagerMSW::ms_pfnRasEnumConnections = 0;
300RASENUMENTRIES wxDialUpManagerMSW::ms_pfnRasEnumEntries = 0;
301RASGETCONNECTSTATUS wxDialUpManagerMSW::ms_pfnRasGetConnectStatus = 0;
302RASGETERRORSTRING wxDialUpManagerMSW::ms_pfnRasGetErrorString = 0;
303RASHANGUP wxDialUpManagerMSW::ms_pfnRasHangUp = 0;
304RASGETPROJECTIONINFO wxDialUpManagerMSW::ms_pfnRasGetProjectionInfo = 0;
305RASCREATEPHONEBOOKENTRY wxDialUpManagerMSW::ms_pfnRasCreatePhonebookEntry = 0;
306RASEDITPHONEBOOKENTRY wxDialUpManagerMSW::ms_pfnRasEditPhonebookEntry = 0;
307RASSETENTRYDIALPARAMS wxDialUpManagerMSW::ms_pfnRasSetEntryDialParams = 0;
308RASGETENTRYDIALPARAMS wxDialUpManagerMSW::ms_pfnRasGetEntryDialParams = 0;
309RASENUMDEVICES wxDialUpManagerMSW::ms_pfnRasEnumDevices = 0;
310RASGETCOUNTRYINFO wxDialUpManagerMSW::ms_pfnRasGetCountryInfo = 0;
311RASGETENTRYPROPERTIES wxDialUpManagerMSW::ms_pfnRasGetEntryProperties = 0;
312RASSETENTRYPROPERTIES wxDialUpManagerMSW::ms_pfnRasSetEntryProperties = 0;
313RASRENAMEENTRY wxDialUpManagerMSW::ms_pfnRasRenameEntry = 0;
314RASDELETEENTRY wxDialUpManagerMSW::ms_pfnRasDeleteEntry = 0;
315RASVALIDATEENTRYNAME wxDialUpManagerMSW::ms_pfnRasValidateEntryName = 0;
316RASCONNECTIONNOTIFICATION wxDialUpManagerMSW::ms_pfnRasConnectionNotification = 0;
317
318int wxDialUpManagerMSW::ms_userSpecifiedOnlineStatus = -1;
319int wxDialUpManagerMSW::ms_isConnected = -1;
320wxDialUpManagerMSW *wxDialUpManagerMSW::ms_dialer = NULL;
321
322// ----------------------------------------------------------------------------
323// ctor and dtor: the dynamic linking happens here
324// ----------------------------------------------------------------------------
325
326// the static creator function is implemented here
327wxDialUpManager *wxDialUpManager::Create()
328{
329 return new wxDialUpManagerMSW;
330}
331
332#ifdef __VISUALC__
333 // warning about "'this' : used in base member initializer list" - so what?
334 #pragma warning(disable:4355)
335#endif // VC++
336
337wxDialUpManagerMSW::wxDialUpManagerMSW()
4522bb3e
VZ
338 : m_timerStatusPolling(this),
339 m_dllRas(_T("RASAPI32"))
a0b4c98b
VZ
340{
341 // initialize our data
342 m_hThread = 0;
343
4f89dbc4
RL
344 if ( !m_dllRas.IsLoaded() )
345 {
346 wxLogError(_("Dial up functions are unavailable because the remote access service (RAS) is not installed on this machine. Please install it."));
347 }
1c25d245 348 else if ( !ms_pfnRasDial )
a0b4c98b 349 {
4f89dbc4
RL
350 // resolve the functions we need
351
352 // this will contain the name of the function we failed to resolve
353 // if any at the end
354 const char *funcName = NULL;
355
356 // get the function from rasapi32.dll and abort if it's not found
357 #define RESOLVE_RAS_FUNCTION(type, name) \
358 ms_pfn##name = (type)m_dllRas.GetSymbol( wxString(_T(#name)) \
359 + gs_funcSuffix); \
360 if ( !ms_pfn##name ) \
361 { \
362 funcName = #name; \
363 goto exit; \
364 }
365
366 // a variant of above macro which doesn't abort if the function is
367 // not found in the DLL
368 #define RESOLVE_OPTIONAL_RAS_FUNCTION(type, name) \
369 ms_pfn##name = (type)m_dllRas.GetSymbol( wxString(_T(#name)) \
370 + gs_funcSuffix);
371
372 RESOLVE_RAS_FUNCTION(RASDIAL, RasDial);
373 RESOLVE_RAS_FUNCTION(RASENUMCONNECTIONS, RasEnumConnections);
374 RESOLVE_RAS_FUNCTION(RASENUMENTRIES, RasEnumEntries);
375 RESOLVE_RAS_FUNCTION(RASGETCONNECTSTATUS, RasGetConnectStatus);
376 RESOLVE_RAS_FUNCTION(RASGETERRORSTRING, RasGetErrorString);
377 RESOLVE_RAS_FUNCTION(RASHANGUP, RasHangUp);
378 RESOLVE_RAS_FUNCTION(RASGETENTRYDIALPARAMS, RasGetEntryDialParams);
379
380 // suppress error messages about missing (non essential) functions
a0b4c98b 381 {
4f89dbc4
RL
382 wxLogNull noLog;
383
384 RESOLVE_OPTIONAL_RAS_FUNCTION(RASGETPROJECTIONINFO, RasGetProjectionInfo);
385 RESOLVE_OPTIONAL_RAS_FUNCTION(RASCREATEPHONEBOOKENTRY, RasCreatePhonebookEntry);
386 RESOLVE_OPTIONAL_RAS_FUNCTION(RASEDITPHONEBOOKENTRY, RasEditPhonebookEntry);
387 RESOLVE_OPTIONAL_RAS_FUNCTION(RASSETENTRYDIALPARAMS, RasSetEntryDialParams);
388 RESOLVE_OPTIONAL_RAS_FUNCTION(RASGETENTRYPROPERTIES, RasGetEntryProperties);
389 RESOLVE_OPTIONAL_RAS_FUNCTION(RASSETENTRYPROPERTIES, RasSetEntryProperties);
390 RESOLVE_OPTIONAL_RAS_FUNCTION(RASRENAMEENTRY, RasRenameEntry);
391 RESOLVE_OPTIONAL_RAS_FUNCTION(RASDELETEENTRY, RasDeleteEntry);
392 RESOLVE_OPTIONAL_RAS_FUNCTION(RASVALIDATEENTRYNAME, RasValidateEntryName);
393 RESOLVE_OPTIONAL_RAS_FUNCTION(RASGETCOUNTRYINFO, RasGetCountryInfo);
394 RESOLVE_OPTIONAL_RAS_FUNCTION(RASENUMDEVICES, RasEnumDevices);
395 RESOLVE_OPTIONAL_RAS_FUNCTION(RASCONNECTIONNOTIFICATION, RasConnectionNotification);
a0b4c98b 396 }
a0b4c98b 397
4f89dbc4
RL
398 // keep your preprocessor name space clean
399 #undef RESOLVE_RAS_FUNCTION
400 #undef RESOLVE_OPTIONAL_RAS_FUNCTION
a0b4c98b
VZ
401
402exit:
4f89dbc4
RL
403 if ( funcName )
404 {
405 static const wxChar *msg = wxTRANSLATE(
f6bcfd97
BP
406"The version of remote access service (RAS) installed on this machine is too\
407old, please upgrade (the following required function is missing: %s)."
4f89dbc4 408 );
a0b4c98b 409
4f89dbc4
RL
410 wxLogError(wxGetTranslation(msg), funcName);
411 m_dllRas.Unload();
412 return;
a0b4c98b
VZ
413 }
414 }
415
416 // enable auto check by default
417 EnableAutoCheckOnlineStatus(0);
418}
419
420wxDialUpManagerMSW::~wxDialUpManagerMSW()
421{
422 CleanUpThreadData();
a0b4c98b
VZ
423}
424
425// ----------------------------------------------------------------------------
426// helper functions
427// ----------------------------------------------------------------------------
428
429wxString wxDialUpManagerMSW::GetErrorString(DWORD error)
430{
431 wxChar buffer[512]; // this should be more than enough according to MS docs
432 DWORD dwRet = ms_pfnRasGetErrorString(error, buffer, WXSIZEOF(buffer));
433 switch ( dwRet )
434 {
435 case ERROR_INVALID_PARAMETER:
436 // this was a standard Win32 error probably
437 return wxString(wxSysErrorMsg(error));
438
439 default:
440 {
f6bcfd97
BP
441 wxLogSysError(dwRet,
442 _("Failed to retrieve text of RAS error message"));
a0b4c98b
VZ
443
444 wxString msg;
445 msg.Printf(_("unknown error (error code %08x)."), error);
446 return msg;
447 }
448
449 case 0:
450 // we want the error message to start from a lower case letter
451 buffer[0] = wxTolower(buffer[0]);
452
453 return wxString(buffer);
454 }
455}
456
457HRASCONN wxDialUpManagerMSW::FindActiveConnection()
458{
459 // enumerate connections
460 DWORD cbBuf = sizeof(RASCONN);
461 LPRASCONN lpRasConn = (LPRASCONN)malloc(cbBuf);
462 if ( !lpRasConn )
463 {
464 // out of memory
465 return 0;
466 }
467
468 lpRasConn->dwSize = sizeof(RASCONN);
469
470 DWORD nConnections = 0;
471 DWORD dwRet = ERROR_BUFFER_TOO_SMALL;
472
473 while ( dwRet == ERROR_BUFFER_TOO_SMALL )
474 {
475 dwRet = ms_pfnRasEnumConnections(lpRasConn, &cbBuf, &nConnections);
476
477 if ( dwRet == ERROR_BUFFER_TOO_SMALL )
478 {
479 LPRASCONN lpRasConnOld = lpRasConn;
480 lpRasConn = (LPRASCONN)realloc(lpRasConn, cbBuf);
481 if ( !lpRasConn )
482 {
483 // out of memory
484 free(lpRasConnOld);
485
486 return 0;
487 }
488 }
489 else if ( dwRet == 0 )
490 {
491 // ok, success
492 break;
493 }
494 else
495 {
496 // an error occured
497 wxLogError(_("Cannot find active dialup connection: %s"),
5b09e9c2 498 GetErrorString(dwRet).c_str());
a0b4c98b
VZ
499 return 0;
500 }
501 }
502
503 HRASCONN hrasconn;
504
505 switch ( nConnections )
506 {
507 case 0:
508 // no connections
509 hrasconn = 0;
510 break;
511
512 default:
513 // more than 1 connection - we don't know what to do with this
514 // case, so give a warning but continue (taking the first
515 // connection) - the warning is really needed because this function
516 // is used, for example, to select the connection to hang up and so
517 // we may hang up the wrong connection here...
f6bcfd97 518 wxLogWarning(_("Several active dialup connections found, choosing one randomly."));
a0b4c98b
VZ
519 // fall through
520
521 case 1:
522 // exactly 1 connection, great
523 hrasconn = lpRasConn->hrasconn;
524 }
525
526 free(lpRasConn);
527
528 return hrasconn;
529}
530
531void wxDialUpManagerMSW::CleanUpThreadData()
532{
533 if ( m_hThread )
534 {
535 if ( !SetEvent(m_data.hEventQuit) )
536 {
fcec6429 537 wxLogLastError(_T("SetEvent(RasThreadQuit)"));
a0b4c98b
VZ
538 }
539
540 CloseHandle(m_hThread);
541
542 m_hThread = 0;
543 }
544
545 if ( m_data.hWnd )
546 {
547 DestroyWindow(m_data.hWnd);
548
549 m_data.hWnd = 0;
550 }
551
552 if ( m_data.hEventQuit )
553 {
554 CloseHandle(m_data.hEventQuit);
555
556 m_data.hEventQuit = 0;
557 }
558
559 if ( m_data.hEventRas )
560 {
561 CloseHandle(m_data.hEventRas);
562
563 m_data.hEventRas = 0;
564 }
565}
566
567// ----------------------------------------------------------------------------
568// connection status
569// ----------------------------------------------------------------------------
570
571void wxDialUpManagerMSW::CheckRasStatus()
572{
573 // use int, not bool to compare with -1
574 int isConnected = FindActiveConnection() != 0;
575 if ( isConnected != ms_isConnected )
576 {
577 if ( ms_isConnected != -1 )
578 {
579 // notify the program
580 NotifyApp(isConnected != 0);
581 }
582 // else: it's the first time we're called, just update the flag
583
584 ms_isConnected = isConnected;
585 }
586}
587
588void wxDialUpManagerMSW::NotifyApp(bool connected, bool fromOurselves) const
589{
590 wxDialUpEvent event(connected, fromOurselves);
591 (void)wxTheApp->ProcessEvent(event);
592}
593
594// this function is called whenever the status of any RAS connection on this
595// machine changes by RAS itself
596void wxDialUpManagerMSW::OnConnectStatusChange()
597{
598 // we know that status changed, but we don't know whether we're connected
599 // or not - so find it out
600 CheckRasStatus();
601}
602
603// this function is called by our callback which we give to RasDial() when
604// calling it asynchronously
605void wxDialUpManagerMSW::OnDialProgress(RASCONNSTATE rasconnstate,
606 DWORD dwError)
607{
608 if ( !GetDialer() )
609 {
610 // this probably means that CancelDialing() was called and we get
611 // "disconnected" notification
612 return;
613 }
614
615 // we're only interested in 2 events: connected and disconnected
616 if ( dwError )
617 {
618 wxLogError(_("Failed to establish dialup connection: %s"),
5b09e9c2 619 GetErrorString(dwError).c_str());
a0b4c98b
VZ
620
621 // we should still call RasHangUp() if we got a non 0 connection
622 if ( ms_hRasConnection )
623 {
624 ms_pfnRasHangUp(ms_hRasConnection);
625 ms_hRasConnection = 0;
626 }
627
628 ms_dialer = NULL;
629
630 NotifyApp(FALSE /* !connected */, TRUE /* we dialed ourselves */);
631 }
632 else if ( rasconnstate == RASCS_Connected )
633 {
634 ms_isConnected = TRUE;
635 ms_dialer = NULL;
636
637 NotifyApp(TRUE /* connected */, TRUE /* we dialed ourselves */);
638 }
639}
640
641// ----------------------------------------------------------------------------
642// implementation of wxDialUpManager functions
643// ----------------------------------------------------------------------------
644
645bool wxDialUpManagerMSW::IsOk() const
646{
4f89dbc4 647 return m_dllRas.IsLoaded();
a0b4c98b
VZ
648}
649
2690830e
VZ
650size_t wxDialUpManagerMSW::GetISPNames(wxArrayString& names) const
651{
652 // fetch the entries
653 DWORD size = sizeof(RASENTRYNAME);
654 RASENTRYNAME *rasEntries = (RASENTRYNAME *)malloc(size);
655 rasEntries->dwSize = sizeof(RASENTRYNAME);
656
657 DWORD nEntries;
658 DWORD dwRet;
659 do
660 {
661 dwRet = ms_pfnRasEnumEntries
662 (
663 NULL, // reserved
664 NULL, // default phone book (or all)
665 rasEntries, // [out] buffer for the entries
666 &size, // [in/out] size of the buffer
667 &nEntries // [out] number of entries fetched
668 );
669
670 if ( dwRet == ERROR_BUFFER_TOO_SMALL )
671 {
672 // reallocate the buffer
673 rasEntries = (RASENTRYNAME *)realloc(rasEntries, size);
674 }
675 else if ( dwRet != 0 )
676 {
677 // some other error - abort
5b09e9c2
VZ
678 wxLogError(_("Failed to get ISP names: %s"),
679 GetErrorString(dwRet).c_str());
2690830e
VZ
680
681 free(rasEntries);
682
683 return 0u;
684 }
685 }
686 while ( dwRet != 0 );
687
688 // process them
689 names.Empty();
690 for ( size_t n = 0; n < (size_t)nEntries; n++ )
691 {
692 names.Add(rasEntries[n].szEntryName);
693 }
694
695 free(rasEntries);
696
697 // return the number of entries
698 return names.GetCount();
699}
700
a0b4c98b
VZ
701bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP,
702 const wxString& username,
703 const wxString& password,
704 bool async)
705{
2690830e 706 // check preconditions
223d09f6 707 wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
708
709 if ( ms_hRasConnection )
710 {
223d09f6 711 wxFAIL_MSG(wxT("there is already an active connection"));
a0b4c98b
VZ
712
713 return TRUE;
714 }
715
2690830e
VZ
716 // get the default ISP if none given
717 wxString entryName(nameOfISP);
718 if ( !entryName )
719 {
720 wxArrayString names;
721 size_t count = GetISPNames(names);
722 switch ( count )
723 {
724 case 0:
725 // no known ISPs, abort
726 wxLogError(_("Failed to connect: no ISP to dial."));
727
728 return FALSE;
729
730 case 1:
731 // only one ISP, choose it
732 entryName = names[0u];
733 break;
734
735 default:
736 // several ISPs, let the user choose
737 {
738 wxString *strings = new wxString[count];
739 for ( size_t i = 0; i < count; i++ )
740 {
741 strings[i] = names[i];
742 }
743
744 entryName = wxGetSingleChoice
745 (
746 _("Choose ISP to dial"),
f6bcfd97 747 _("Please choose which ISP do you want to connect to"),
2690830e
VZ
748 count,
749 strings
750 );
751
752 delete [] strings;
753
754 if ( !entryName )
755 {
756 // cancelled by user
757 return FALSE;
758 }
759 }
760 }
761 }
762
a0b4c98b
VZ
763 RASDIALPARAMS rasDialParams;
764 rasDialParams.dwSize = sizeof(rasDialParams);
f6bcfd97 765 wxStrncpy(rasDialParams.szEntryName, entryName, RAS_MaxEntryName);
2690830e
VZ
766
767 // do we have the username and password?
768 if ( !username || !password )
769 {
770 BOOL gotPassword;
771 DWORD dwRet = ms_pfnRasGetEntryDialParams
772 (
773 NULL, // default phonebook
774 &rasDialParams, // [in/out] the params of this entry
775 &gotPassword // [out] did we get password?
776 );
777
778 if ( dwRet != 0 )
779 {
780 wxLogError(_("Failed to connect: missing username/password."));
781
782 return FALSE;
783 }
784 }
4f89dbc4
RL
785 else
786 {
787 wxStrncpy(rasDialParams.szUserName, username, UNLEN);
788 wxStrncpy(rasDialParams.szPassword, password, PWLEN);
789 }
2690830e 790
4f89dbc4 791 // default values for other fields
a0b4c98b
VZ
792 rasDialParams.szPhoneNumber[0] = '\0';
793 rasDialParams.szCallbackNumber[0] = '\0';
794 rasDialParams.szCallbackNumber[0] = '\0';
795
a0b4c98b
VZ
796 rasDialParams.szDomain[0] = '*';
797 rasDialParams.szDomain[1] = '\0';
798
799 // apparently, this is not really necessary - passing NULL instead of the
800 // phone book has the same effect
801#if 0
802 wxString phoneBook;
803 if ( wxGetOsVersion() == wxWINDOWS_NT )
804 {
805 // first get the length
806 UINT nLen = ::GetSystemDirectory(NULL, 0);
807 nLen++;
808
809 if ( !::GetSystemDirectory(phoneBook.GetWriteBuf(nLen), nLen) )
810 {
811 wxLogSysError(_("Cannot find the location of address book file"));
812 }
813
814 phoneBook.UngetWriteBuf();
815
816 // this is the default phone book
817 phoneBook << "\\ras\\rasphone.pbk";
818 }
819#endif // 0
820
821 // TODO may be we should disable auto check while async dialing is in
822 // progress?
823
824 ms_dialer = this;
825
826 DWORD dwRet = ms_pfnRasDial
827 (
1c25d245
VZ
828 NULL, // no extended features
829 NULL, // default phone book file (NT only)
a0b4c98b 830 &rasDialParams,
1c25d245
VZ
831 0, // use callback for notifications
832 async ? (void *)wxRasDialFunc // cast needed for gcc 3.1
833 : 0, // no notifications, sync operation
a0b4c98b
VZ
834 &ms_hRasConnection
835 );
836
837 if ( dwRet != 0 )
838 {
bf9b6266 839 // can't pass a wxWCharBuffer through ( ... )
a0b4c98b 840 wxLogError(_("Failed to %s dialup connection: %s"),
5438a566 841 wxString(async ? _("initiate") : _("establish")).c_str(),
5b09e9c2 842 GetErrorString(dwRet).c_str());
a0b4c98b
VZ
843
844 // we should still call RasHangUp() if we got a non 0 connection
845 if ( ms_hRasConnection )
846 {
847 ms_pfnRasHangUp(ms_hRasConnection);
848 ms_hRasConnection = 0;
849 }
850
851 ms_dialer = NULL;
852
853 return FALSE;
854 }
855
856 // for async dialing, we're not yet connected
857 if ( !async )
858 {
859 ms_isConnected = TRUE;
860 }
861
862 return TRUE;
863}
864
865bool wxDialUpManagerMSW::IsDialing() const
866{
867 return GetDialer() != NULL;
868}
869
870bool wxDialUpManagerMSW::CancelDialing()
871{
872 if ( !GetDialer() )
873 {
874 // silently ignore
875 return FALSE;
876 }
877
223d09f6 878 wxASSERT_MSG( ms_hRasConnection, wxT("dialing but no connection?") );
a0b4c98b
VZ
879
880 ms_dialer = NULL;
881
882 return HangUp();
883}
884
885bool wxDialUpManagerMSW::HangUp()
886{
223d09f6 887 wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
888
889 // we may terminate either the connection we initiated or another one which
890 // is active now
891 HRASCONN hRasConn;
892 if ( ms_hRasConnection )
893 {
894 hRasConn = ms_hRasConnection;
895
896 ms_hRasConnection = 0;
897 }
898 else
899 {
900 hRasConn = FindActiveConnection();
901 }
902
903 if ( !hRasConn )
904 {
905 wxLogError(_("Cannot hang up - no active dialup connection."));
906
907 return FALSE;
908 }
909
910 DWORD dwRet = ms_pfnRasHangUp(hRasConn);
911 if ( dwRet != 0 )
912 {
913 wxLogError(_("Failed to terminate the dialup connection: %s"),
5b09e9c2 914 GetErrorString(dwRet).c_str());
a0b4c98b
VZ
915 }
916
917 ms_isConnected = FALSE;
918
919 return TRUE;
920}
921
2690830e
VZ
922bool wxDialUpManagerMSW::IsAlwaysOnline() const
923{
19caf229
VZ
924 // assume no permanent connection by default
925 bool isAlwaysOnline = FALSE;
2690830e 926
19caf229 927 // try to use WinInet functions
4f89dbc4
RL
928
929 // NB: we could probably use wxDynamicLibrary here just as well,
930 // but we allow multiple instances of wxDialUpManagerMSW so
931 // we might as well use the ref counted version here too.
932
4522bb3e 933 wxDynamicLibrary hDll(_T("WININET"));
4f89dbc4 934 if ( hDll.IsLoaded() )
2690830e 935 {
5a56be28 936 typedef BOOL (WINAPI *INTERNETGETCONNECTEDSTATE)(LPDWORD, DWORD);
2690830e
VZ
937 INTERNETGETCONNECTEDSTATE pfnInternetGetConnectedState;
938
939 #define RESOLVE_FUNCTION(type, name) \
4f89dbc4 940 pfn##name = (type)hDll.GetSymbol(_T(#name))
2690830e
VZ
941
942 RESOLVE_FUNCTION(INTERNETGETCONNECTEDSTATE, InternetGetConnectedState);
943
944 if ( pfnInternetGetConnectedState )
945 {
946 DWORD flags = 0;
947 if ( pfnInternetGetConnectedState(&flags, 0 /* reserved */) )
948 {
949 // there is some connection to the net, see of which type
19caf229
VZ
950 isAlwaysOnline = (flags & (INTERNET_CONNECTION_LAN |
951 INTERNET_CONNECTION_PROXY)) != 0;
2690830e 952 }
19caf229 953 //else: no Internet connection at all
2690830e
VZ
954 }
955 }
956
19caf229 957 return isAlwaysOnline;
2690830e
VZ
958}
959
a0b4c98b
VZ
960bool wxDialUpManagerMSW::IsOnline() const
961{
223d09f6 962 wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") );
a0b4c98b 963
90e9494a
VZ
964 if ( IsAlwaysOnline() )
965 {
966 // always => now
967 return true;
968 }
969
a0b4c98b
VZ
970 if ( ms_userSpecifiedOnlineStatus != -1 )
971 {
972 // user specified flag overrides our logic
973 return ms_userSpecifiedOnlineStatus != 0;
974 }
975 else
976 {
977 // return TRUE if there is at least one active connection
978 return FindActiveConnection() != 0;
979 }
980}
981
982void wxDialUpManagerMSW::SetOnlineStatus(bool isOnline)
983{
223d09f6 984 wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
985
986 ms_userSpecifiedOnlineStatus = isOnline;
987}
988
989bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds)
990{
223d09f6 991 wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
992
993 bool ok = ms_pfnRasConnectionNotification != 0;
994
995 if ( ok )
996 {
997 // we're running under NT 4.0, Windows 98 or later and can use
998 // RasConnectionNotification() to be notified by a secondary thread
999
1000 // first, see if we don't have this thread already running
1001 if ( m_hThread != 0 )
1002 {
1003 DWORD dwSuspendCount = 2;
1004 while ( dwSuspendCount > 1 )
1005 {
1006 dwSuspendCount = ResumeThread(m_hThread);
1007 if ( dwSuspendCount == (DWORD)-1 )
1008 {
f6bcfd97 1009 wxLogLastError(wxT("ResumeThread(RasThread)"));
a0b4c98b
VZ
1010
1011 ok = FALSE;
1012 }
1013 }
1014
1015 if ( ok )
1016 {
1017 return TRUE;
1018 }
1019 }
1020 }
1021
1022 // create all the stuff we need to be notified about RAS connection
1023 // status change
1024
1025 if ( ok )
1026 {
1027 // first create an event to wait on
1028 m_data.hEventRas = CreateEvent
1029 (
1030 NULL, // security attribute (default)
1031 FALSE, // manual reset (not)
1032 FALSE, // initial state (not signaled)
1033 NULL // name (no)
1034 );
1035 if ( !m_data.hEventRas )
1036 {
f6bcfd97 1037 wxLogLastError(wxT("CreateEvent(RasStatus)"));
a0b4c98b
VZ
1038
1039 ok = FALSE;
1040 }
1041 }
1042
1043 if ( ok )
1044 {
1045 // create the event we use to quit the thread
1046 m_data.hEventQuit = CreateEvent(NULL, FALSE, FALSE, NULL);
1047 if ( !m_data.hEventQuit )
1048 {
f6bcfd97 1049 wxLogLastError(wxT("CreateEvent(RasThreadQuit)"));
a0b4c98b
VZ
1050
1051 CleanUpThreadData();
1052
1053 ok = FALSE;
1054 }
1055 }
1056
2690830e 1057 if ( ok && !ms_hwndRas )
a0b4c98b
VZ
1058 {
1059 // create a hidden window to receive notification about connections
1060 // status change
03baf031
VZ
1061 extern const wxChar *wxCanvasClassName;
1062 ms_hwndRas = ::CreateWindow(wxCanvasClassName, NULL,
2690830e
VZ
1063 0, 0, 0, 0,
1064 0, NULL,
1065 (HMENU)NULL, wxGetInstance(), 0);
1066 if ( !ms_hwndRas )
a0b4c98b 1067 {
f6bcfd97 1068 wxLogLastError(wxT("CreateWindow(RasHiddenWindow)"));
a0b4c98b
VZ
1069
1070 CleanUpThreadData();
1071
1072 ok = FALSE;
1073 }
1074
1075 // and subclass it
1076 FARPROC windowProc = MakeProcInstance
1077 (
1078 (FARPROC)wxRasStatusWindowProc,
1079 wxGetInstance()
1080 );
1081
2690830e 1082 ::SetWindowLong(ms_hwndRas, GWL_WNDPROC, (LONG) windowProc);
a0b4c98b
VZ
1083 }
1084
2690830e
VZ
1085 m_data.hWnd = ms_hwndRas;
1086
a0b4c98b
VZ
1087 if ( ok )
1088 {
1089 // start the secondary thread
1090 m_data.dialUpManager = this;
1091
1092 DWORD tid;
1093 m_hThread = CreateThread
1094 (
1095 NULL,
1096 0,
1097 (LPTHREAD_START_ROUTINE)wxRasMonitorThread,
1098 (void *)&m_data,
1099 0,
1100 &tid
1101 );
1102
1103 if ( !m_hThread )
1104 {
f6bcfd97 1105 wxLogLastError(wxT("CreateThread(RasStatusThread)"));
a0b4c98b
VZ
1106
1107 CleanUpThreadData();
1108 }
1109 }
1110
1111 if ( ok )
1112 {
1113 // start receiving RAS notifications
1114 DWORD dwRet = ms_pfnRasConnectionNotification
1115 (
1116 (HRASCONN)INVALID_HANDLE_VALUE,
1117 m_data.hEventRas,
1118 3 /* RASCN_Connection | RASCN_Disconnection */
1119 );
1120
1121 if ( dwRet != 0 )
1122 {
223d09f6 1123 wxLogDebug(wxT("RasConnectionNotification() failed: %s"),
5b09e9c2 1124 GetErrorString(dwRet).c_str());
a0b4c98b
VZ
1125
1126 CleanUpThreadData();
1127 }
1128 else
1129 {
1130 return TRUE;
1131 }
1132 }
1133
1134 // we're running under Windows 95 and have to poll ourselves
1135 // (or, alternatively, the code above for NT/98 failed)
1136 m_timerStatusPolling.Stop();
1137 if ( nSeconds == 0 )
1138 {
1139 // default value
1140 nSeconds = 60;
1141 }
1142 m_timerStatusPolling.Start(nSeconds * 1000);
1143
1144 return TRUE;
1145}
1146
1147void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus()
1148{
223d09f6 1149 wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
1150
1151 if ( m_hThread )
1152 {
1153 // we have running secondary thread, it's just enough to suspend it
1154 if ( SuspendThread(m_hThread) == (DWORD)-1 )
1155 {
f6bcfd97 1156 wxLogLastError(wxT("SuspendThread(RasThread)"));
a0b4c98b
VZ
1157 }
1158 }
1159 else
1160 {
1161 // even simpler - just stop the timer
1162 m_timerStatusPolling.Stop();
1163 }
1164}
1165
1166// ----------------------------------------------------------------------------
1167// stubs which don't do anything in MSW version
1168// ----------------------------------------------------------------------------
1169
1170void wxDialUpManagerMSW::SetWellKnownHost(const wxString& WXUNUSED(hostname),
1171 int WXUNUSED(port))
1172{
223d09f6 1173 wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
1174
1175 // nothing to do - we don't use this
1176}
1177
1178void wxDialUpManagerMSW::SetConnectCommand(const wxString& WXUNUSED(dial),
1179 const wxString& WXUNUSED(hangup))
1180{
223d09f6 1181 wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
a0b4c98b
VZ
1182
1183 // nothing to do - we don't use this
1184}
1185
1186// ----------------------------------------------------------------------------
1187// callbacks
1188// ----------------------------------------------------------------------------
1189
1190static DWORD wxRasMonitorThread(wxRasThreadData *data)
1191{
1192 HANDLE handles[2];
1193 handles[0] = data->hEventRas;
1194 handles[1] = data->hEventQuit;
1195
1196 bool cont = TRUE;
1197 while ( cont )
1198 {
1199 DWORD dwRet = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
1200
1201 switch ( dwRet )
1202 {
1203 case WAIT_OBJECT_0:
1204 // RAS connection status changed
1205 SendMessage(data->hWnd, wxWM_RAS_STATUS_CHANGED,
1206 0, (LPARAM)data);
1207 break;
1208
1209 case WAIT_OBJECT_0 + 1:
1210 cont = FALSE;
1211 break;
1212
1213 case WAIT_FAILED:
f6bcfd97 1214 wxLogLastError(wxT("WaitForMultipleObjects(RasMonitor)"));
a0b4c98b
VZ
1215 break;
1216 }
1217 }
1218
1219 return 0;
1220}
1221
1222static LRESULT APIENTRY wxRasStatusWindowProc(HWND hWnd, UINT message,
1223 WPARAM wParam, LPARAM lParam)
1224{
cd6af1cb 1225 switch ( message )
a0b4c98b 1226 {
cd6af1cb
VZ
1227 case wxWM_RAS_STATUS_CHANGED:
1228 {
1229 wxRasThreadData *data = (wxRasThreadData *)lParam;
1230 data->dialUpManager->OnConnectStatusChange();
1231 }
1232 break;
2690830e 1233
cd6af1cb
VZ
1234 case wxWM_RAS_DIALING_PROGRESS:
1235 {
1236 wxDialUpManagerMSW *dialMan = wxDialUpManagerMSW::GetDialer();
1237
1238 dialMan->OnDialProgress((RASCONNSTATE)wParam, lParam);
1239 }
1240 break;
1241
1242 default:
1243 return ::DefWindowProc(hWnd, message, wParam, lParam);
2690830e 1244 }
a0b4c98b
VZ
1245
1246 return 0;
1247}
1248
2eb10e2a 1249static void WINAPI wxRasDialFunc(UINT WXUNUSED(unMsg),
a0b4c98b
VZ
1250 RASCONNSTATE rasconnstate,
1251 DWORD dwError)
1252{
1253 wxDialUpManagerMSW *dialUpManager = wxDialUpManagerMSW::GetDialer();
1254
223d09f6 1255 wxCHECK_RET( dialUpManager, wxT("who started to dial then?") );
a0b4c98b 1256
2690830e
VZ
1257 SendMessage(dialUpManager->GetRasWindow(), wxWM_RAS_DIALING_PROGRESS,
1258 rasconnstate, dwError);
a0b4c98b
VZ
1259}
1260
1c25d245
VZ
1261#endif // __BORLANDC__
1262
a0b4c98b 1263#endif // wxUSE_DIALUP_MANAGER
4f89dbc4 1264