|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
, ?+ }5 Q4 K. \有一个RasDial拨号函数的定义如下:9 u: l+ c+ L. m7 i( e
DWORD RasDial(, J! S; ?% u9 z/ J2 S( Z
LPRASDIALEXTENSIONS dialExtensions, 4 m8 u+ {4 t9 |/ Q" `
LPTSTR phoneBookPath , ! C2 G0 P; ?- J5 B( i( j
LPRASDIALPARAMS rasDialParam ,
% r6 @7 F( K: sDWORD NotifierType, $ J: T& S+ p" S4 B& b
LPVOID notifier, ; `3 c, t: h1 `1 i5 u
LPHRASCONN pRasConn );3 g& \: c! q+ w# J" p @
; X% H% r% }* G' _- @
我的MSDN的解说如下:) }; S, |8 Y& T5 G) W5 H" }
Parameters; Q* X {. Y5 c
dialExtensions . h! a' I4 L! R
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. + ^5 ~8 [' T/ J* s0 G* K N
phoneBookPath 1 R) Z, `4 q/ d. j- t
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. & [) D [5 |3 f [
rasDialParam / z6 G- M- G" m" V( M- H
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
3 r0 D0 }: d; Q& NThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. 1 }% P4 z! ]5 e. \$ i0 ~
! c/ C5 o6 G3 }# D$ `3 z# LNotifierType 4 j$ {, e& r5 t4 _/ h6 D8 Q
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: % i' L- [5 v ]$ P
Value Description
+ `; t$ F2 B) k2 v! x0 e: V' A0xFFFFFFFF- l* b! O6 l, W5 Q3 I% j
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. 1 m& q H* ]: ~( D) Q/ B
The progress notification message uses the WM_RASDIALEVENT message code.
: a5 V& }" X+ o' T7 d
9 n% U8 Y$ N' q( M, a: i7 \2 D2 `, R3 c) n5 A- s
6 l/ b+ S( [' a' [" Q
1 G r( i, f# F1 t; wnotifier ( m8 x+ q( J3 Y/ r! W
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.
& A+ M0 p+ e ?2 T1 v: @If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. 3 ^: p4 e7 @+ p- m. G6 p
% B9 Q3 V( s) h: g5 w; o- pIf 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: 4 v" p- U* Q( L4 s) H4 n9 r; [5 [0 j: a; y
2 A) }0 b5 e. D/ w7 }The connection is established. In other words, the RAS connection state is RASCS_Connected. # ^( w/ M# p; B2 w+ D- M- w$ T- k
The connection fails. In other words, dwError is nonzero. ; g L- {6 p5 U+ t+ B) r
RasHangUp is called on the connection. 2 Y/ n L8 a8 b" ^4 d
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
# O4 B" B" m# `/ [. L% s% W, W$ ~' ^2 t9 I: N& H+ d' A* n
pRasConn
: X5 r# F/ T2 j, f; d6 w! f! [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. ) X% g; v u* N1 x$ Q8 b; o
Return Values
" w$ n B0 ?6 d H) s1 I0 hZero 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.
% e/ C& |* L, U% O* k5 H
$ L4 ?' j6 O7 c. q5 b+ {Include Raserror.h for definitions of the RAS error codes.
2 T1 f6 ^' a2 T$ N' N1 V! ?# J. q: K4 H( V5 B
Remarks
& D# Z2 K( S: ~3 n7 ?The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
3 S" |- _& ^$ U4 x! Y8 J3 V1 z1 X( V4 H
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.
& e. ^" Q; C4 l0 ?5 j% m
/ j6 D( w; R- W) d* \Errors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection. ' }' ]4 u# U" w2 ]8 a! |# Y
% w* D4 k$ K1 ?; O( q
An 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.
6 L# D2 N7 U0 v; e& L" x1 O2 ]) O6 L- J: c$ ^ C% G7 S
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.
) m ]' `0 @/ u* q* p$ g) _# L5 S' L
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. : M' `' N. a# Z" A. Z$ l e, G! g% u
% n; x& x" N. r$ b8 c6 J4 S' G
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
7 V( I. e* C; uDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
+ u, J1 d$ P4 |/ z第五个参数是个回调函数,一般都定义如下:
+ z( g) d: R& g/ V5 r: F' `% q4 Yvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
$ v' E: k( N4 n& Z, [# f( O' H{
9 C& o: T, u/ a j CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;' G, y$ v7 V8 i* p) Z" _5 B
( T* f3 l3 }2 `- R
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);% Y2 f; N8 Q# s% `& q; I& O
}
7 u+ ^& [2 D7 L这个回调函数将会把拨号的状态POST到各个窗口句柄。5 w/ P+ H2 `; s1 @2 h( q
- p, p4 |6 Y: D$ Q5 D |
|