|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。+ Q7 z4 U; X) d( n* ~3 r
有一个RasDial拨号函数的定义如下:) Q9 Y8 k: | @% S5 y: W2 s
DWORD RasDial(
/ Z6 H% `8 v) sLPRASDIALEXTENSIONS dialExtensions,
9 y9 n0 F/ s. d7 DLPTSTR phoneBookPath , 0 I* S- e1 W3 B0 I$ j
LPRASDIALPARAMS rasDialParam , 0 k T# p. ~$ m6 a- Y4 Z |
DWORD NotifierType,
; I! I7 U0 k- M; V' R+ A9 u5 kLPVOID notifier,
+ o$ b0 H: V. _/ i7 B- s; d: d9 s( {3 kLPHRASCONN pRasConn );2 B% D- b8 n: [( A! @: b- M
1 a8 h% W% p- y: e- K7 M3 R* K我的MSDN的解说如下:
0 ]) \; j: V% E: WParameters
$ }2 [+ e4 _- r: _dialExtensions
. u+ I7 v, t- h( q: |( DThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
0 [( W) x! C: rphoneBookPath 9 Z- @/ s* R% ^8 W. B* _% j% q6 y
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. 1 q9 L0 \7 L( |. |' c& o' G
rasDialParam & J- @4 _! U, o; v
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
8 D7 B) ]0 t. @" G$ jThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. $ T1 a1 ^ b' f5 S$ W
+ {: R( U3 e9 I& H7 F f
NotifierType
% C3 L: r: f6 DSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
- ]- Q& E0 O5 l) O8 g8 [/ MValue Description
/ W. F# R' Z3 ?/ T+ {/ ~0xFFFFFFFF+ G F9 K, G. L- o
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. . ]# E8 T; B& O; \& y g5 z0 b+ D
The progress notification message uses the WM_RASDIALEVENT message code. ' W5 \( P9 b& N9 ^: @
9 x" a+ V/ z9 I# ~. y9 y& J* b6 Q+ r. g5 C3 x" }
. g/ A' U; c0 n% c
# N- e- I& G* enotifier # U( A/ S+ x# Y% U4 u3 h8 Y
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.
+ Q6 V& U2 M$ tIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. ' a# m/ u H: b
V; a+ j2 j5 X4 j/ |. b
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:
9 G/ C( b! v; T+ U" D4 I9 k: \/ u3 z! b: @
The connection is established. In other words, the RAS connection state is RASCS_Connected. $ e/ K" m) v- @* D4 H9 o' \- b
The connection fails. In other words, dwError is nonzero. ; ]; w2 |) g0 ]) {4 _% p9 `+ H, `
RasHangUp is called on the connection.
5 V) S( A, q; O& eThe callback notifications are made in the context of a thread captured during the initial call to RasDial. # x7 f) ?( q' ^: c
- ^5 G- P$ I6 D* MpRasConn
' N. E% u; y' a9 f# gPointer 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.
* ], t8 k. [" f; V# L2 q1 GReturn Values9 y, n6 b% g2 [' R; |
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.
& k& I- E) @) z% B/ q. S0 c
, ~) d+ G$ U- S1 w& k" p P: {Include Raserror.h for definitions of the RAS error codes.
* s2 Q9 F; s7 l+ z' w7 Q
; i) G$ O. W' @0 L- bRemarks
, L v# x* ^5 a1 B7 ]3 cThe szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
! m: |( n% l" ~, p
7 S. E0 `! @7 \; i6 lRasDial 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.
" i4 f+ i( H3 j) z1 n5 L! K/ h0 c [$ y5 z5 h3 p, x5 g7 a+ K
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. 3 N7 m" y& v C
1 P' l: [4 c7 U; p5 }5 w8 U0 NAn 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. " i: e1 A1 V `
9 Y* x9 r) Q" h# G4 L I
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. ! S" U1 T% ^% u) _% o
; c4 s" ]7 {8 _( f, s1 l$ W6 R
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. ( q3 e5 M3 F9 |) u- Z
% \, T5 |( B! F' J, B
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
. j, p% W% N" n* l& x4 a) ]( Z' gDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);! j/ j; J8 T' z; _
第五个参数是个回调函数,一般都定义如下:8 \& ?4 U9 l* [7 ~/ N- g
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)6 I9 P: r; G, Y+ h
{: u6 E+ F2 v" k. A- z
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
8 m8 b2 \' ~* U2 p# f: p3 ] 2 L/ |1 d& N. Q7 _( K+ v
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
1 S7 y$ T; ]+ E, A! |) B+ J- U}2 n* M0 w& W- U& p) c
这个回调函数将会把拨号的状态POST到各个窗口句柄。' \ d: ?8 a7 U9 b% M
* x) l% t& l9 \; k
|
|