|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。$ q$ f) [$ A9 J$ k, a4 n* O6 W
有一个RasDial拨号函数的定义如下:$ ^" Y/ y" e, E6 n, ~3 h1 w
DWORD RasDial(
% c$ R# \1 [3 W! WLPRASDIALEXTENSIONS dialExtensions,
% R U$ ?8 G( SLPTSTR phoneBookPath ,
. h# A% y# U# h" i/ X2 V/ W) @8 NLPRASDIALPARAMS rasDialParam , ) [0 I' t% L: x
DWORD NotifierType,
7 R, E( z/ R3 m9 T q0 h) V6 V$ BLPVOID notifier,
& }6 n5 R; z+ a: b7 ILPHRASCONN pRasConn );, E7 q; L3 c4 c( b( C' k
4 d5 v9 U( A2 q+ I$ O3 `; F. |! ]我的MSDN的解说如下:
! g1 P/ _" k) x8 iParameters
1 H" h# O9 Z3 E- W& UdialExtensions 2 j* G& g5 L+ i
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 2 q, U3 g& ~2 P( m* |7 |1 X9 h$ b0 E
phoneBookPath % q" i6 B2 T5 N. ]
This parameter is ignored and should be set to NULL. Dial-up networking stores phone-book entries in the registry rather than in a phone-book file.
- z/ b/ R& b8 C6 @" grasDialParam + N' I6 h! d3 U' H6 J1 Y) e: ?
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
: m2 }2 t7 X6 C8 jThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
( W8 c" l5 b l% I+ [
2 o5 Y _8 P; y; }+ o$ l1 UNotifierType . l6 d: R! Z2 X2 j" ]
Specifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: " z% b% {7 U0 k" ?6 s
Value Description
! P! E' C% ~, H" K; _0 _0xFFFFFFFF- Z9 L! R d4 A5 G* g' w" l; p
0xFFFFFFFF The notifier parameter is a handle to a window to receive progress notification messages. In a progress notification message, wParam indicates the connection state (rasconnstate) which the RAS connection is about to enter, while lParam indicates whether or not an error occurred. 5 F3 S% t9 M! e( _. \# n r. X# J
The progress notification message uses the WM_RASDIALEVENT message code. 6 e/ }5 X q1 @5 i9 ]" k a
0 p1 X( Q8 F' c! {
8 c& f; f* \* c k
# |+ P9 D" V- W9 I4 Y; J+ {) o) d3 f% z/ \& ? t, B: i
notifier % U' ]; [2 q" N$ f
Pointer to a window handle to receive RasDial event notifications. If this parameter is not NULL, RasDial sends the window a message for each RasDial event. Additionally, the RasDial call operates asynchronously: RasDial returns immediately, before the connection is established, and uses the window to communicate its progress. ) \' @" ?2 b9 m' Y
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
2 F# C' j* x4 _2 W
7 ]. e' i$ O- a; D& d7 T& zIf notifier is not NULL, notifications to the window can occur at any time after the initial call to RasDial. Notifications end when one of the following events occurs: % Q+ x: M5 N* p7 U' C9 Z
8 x3 D1 W9 O& s/ aThe connection is established. In other words, the RAS connection state is RASCS_Connected. * V$ C8 i, y/ l; F
The connection fails. In other words, dwError is nonzero. # i3 `$ }/ F- K
RasHangUp is called on the connection.
8 Y, V0 C! E: I9 J; M' pThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
6 V1 g* K/ e$ x0 Q! E3 G& F" w
3 }, t/ A% X2 l9 [) _( E9 V2 i4 NpRasConn
9 p9 R/ k& T5 s3 P7 Q4 `Pointer to a variable of type HRASCONN. You must set the HRASCONN variable to NULL before calling RasDial. If RasDial succeeds, it stores a handle to the RAS connection into pRasConn. & F; p3 b) t# k/ r1 `
Return Values
9 H4 O. }1 j" Z+ y- |% ^Zero indicates success. In addition, the function stores a handle to the RAS connection into the variable pointed to by pRasConn. A nonzero error value, either from the set listed in the RAS header file or ERROR_NOT_ENOUGH_MEMORY, indicates failure. 1 c8 \0 L% Y6 L) B9 T& w
0 `! i" d8 }3 S; CInclude Raserror.h for definitions of the RAS error codes.
/ z0 F( [# O+ H0 D+ o' R' {
* E5 m- r* p0 c/ V3 i( Q/ [Remarks- O3 z' j8 L) m4 {. o5 e
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.. x3 k* Y! y; F+ }2 R
9 N! f5 y8 C1 u3 V8 _, H+ ?5 B
RasDial will not automatically display the logon dialog box. This is currently done through the Remote Networking application. Applications are responsible for getting the information from the user.
u7 Y) y$ Q8 W0 f% h* q# p
: G" q+ G0 o, i0 p6 E% Y& E/ Y/ NErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection.
u' Y0 z! A2 X9 ~: ^6 J
1 W3 }. Z g: A! DAn application must eventually call RasHangUp whenever a non-NULL connection handle is stored into pRasConn. This applies even if RasDial returns a nonzero (error) value. , q( o& \. [' k" D
$ H9 H2 j7 t% u6 H8 K# DAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns.
8 M4 ]' M, [3 C3 t' q# q$ y, e* r. \; J( U% w2 Z8 O+ W/ ?9 P
The window handle-based notification only works if the underlying configuration supports the PostMessage function. PostMessage is exposed through the msgque component, which is a part of the GWES module. Event notification through a window handle can only work if GWES is part of the underlying configuration.
# f# A+ l- Y w& I: P4 Q0 j/ j. b# w# U4 P" }! D
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
: _1 l r7 w0 `! O% ^DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
( A# K$ H$ V: i& u第五个参数是个回调函数,一般都定义如下:& X' e9 Y7 s8 ?5 c
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
" p0 _5 H8 d, b$ L2 y* U) Z& }{+ x- X) p" d7 D7 P" d2 n, j
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
7 k, P0 F- J8 \ ( N. x' r- L D7 r9 G
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
2 O ^) C$ e1 Y: @. T- ^}$ Z8 A1 w' t7 R: l) q9 x5 k" h% a' t
这个回调函数将会把拨号的状态POST到各个窗口句柄。
$ y3 S S* P5 f3 [3 I( K% j1 q, a0 D- t& U) C N
|
|