|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
: V1 `- |4 x- U$ N有一个RasDial拨号函数的定义如下:
: |% X/ f+ F* R6 JDWORD RasDial(8 S; }& p# P* U7 j2 U. ^
LPRASDIALEXTENSIONS dialExtensions,
. M, d6 m' t& P2 x* c. t: ULPTSTR phoneBookPath , % h! N' i6 u, x6 K6 j3 d3 H0 T
LPRASDIALPARAMS rasDialParam ,
7 @, Q8 F' X8 G+ J. }( p' MDWORD NotifierType,
6 O4 S! P2 N/ R4 U$ lLPVOID notifier, 2 h& R, {9 r. }. }
LPHRASCONN pRasConn );* P5 g* r/ Z& S; x- b* F
9 Y- }: Y" Z' s8 G* O3 `
我的MSDN的解说如下:
R* ]# S, r; F# W TParameters; m2 j0 ~$ m7 S. k; I$ [
dialExtensions
+ n, b0 d7 m# zThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
0 J b! s4 H3 Q2 [& x1 ]$ `phoneBookPath $ k- X8 c m. I3 q/ h& {8 @: ] D
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.
5 Q) k# {/ Z; TrasDialParam 6 [' g2 C2 b+ g; }
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. 0 Z" d! `/ `* N2 \1 H
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
; C% \: r+ C4 q& B' V% n' E6 Y, J; G4 x3 o
NotifierType
. `) ]. {) v% m3 U OSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: & a9 ^3 m$ r: ^! ?! j6 T9 ^" R
Value Description , K; X* h, n% }* D2 _, F( c
0xFFFFFFFF$ j$ |$ K/ L& d; Q
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.
/ E5 f% _0 w0 |$ U3 Z: [5 L The progress notification message uses the WM_RASDIALEVENT message code. 6 q r' ^4 O0 R. k+ S8 c: @' Y0 n
) h/ M8 Y6 n0 R# \2 T6 _
' E; p* E1 U( h5 n% n( B X) p& L3 D/ R
, ~" R d( c3 c/ G, h# {4 rnotifier ) }5 R G$ h# h2 M& V$ F# v* j
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. ]+ l- L( z! D T
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. 1 P# b. J* x8 {: V
, [& X3 N7 Z( }0 w+ \# \, _6 j
If 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: # \! Q0 G/ N7 G* d* G7 q* s) S9 V
7 Y5 e _2 Z7 {" s1 e5 T2 ^" HThe connection is established. In other words, the RAS connection state is RASCS_Connected. % \3 `/ C9 ]9 K$ `" g
The connection fails. In other words, dwError is nonzero. ! ^/ W: k& @1 T$ V2 J! x
RasHangUp is called on the connection.
4 ^4 U: a# `* ?* tThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
! a5 q% l! s" ]- n l# R, x! J
0 A+ t! `1 D" k9 gpRasConn . W# e+ M6 R$ y, x) d, V
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.
F5 I4 l+ w6 w* ^! {Return Values$ ^. e* @" z* f
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.
' H8 Y3 g5 m% ~, a
* O: v9 G( N- c9 C" YInclude Raserror.h for definitions of the RAS error codes.) w( ^/ k5 d% V* ~, c- Q* y7 S- k
. x, [' H% g) v5 O; `+ i* @Remarks) e* z! B% V& S! L
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.( i, s" ?; C; ^
/ p9 O! n5 f5 e. ~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.
Q* E3 K2 ^ E1 W5 e$ c6 Q N6 @
; N/ O9 m2 x/ }+ Q$ cErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection. & ~* [1 o2 _6 k9 o* [: `8 l. b
- o) a' c' ^3 V' m- |' h, }5 c8 cAn 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.
9 D3 m* W4 i" E7 q5 Z, \3 p. o1 r* }
An application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns. * v( C2 m/ L6 g
4 k, J; G% V4 \% zThe 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.
' S/ W/ q4 z# B3 T" x4 f
7 g7 E3 J7 j. N' P' \3 M看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号' _) B6 }8 Q. b3 U$ l
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
" G$ l2 X, I; p. @! ^4 Z第五个参数是个回调函数,一般都定义如下:6 s; P$ g6 X) g
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)2 Y8 y, v3 \3 h5 w* E' d4 ?9 U
{8 [( n1 f/ D( K3 I
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;5 B3 q6 D0 V* }( {$ [; W
2 a1 `0 x! x6 S' r. }* v# ]1 A RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);0 r' }' F! }9 E" r
}. N* N( c2 h3 a5 |
这个回调函数将会把拨号的状态POST到各个窗口句柄。
N7 s' {3 l) O9 _2 n6 y' f! _- r6 @9 ]
|
|