|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。2 W* k# z; |8 z3 z2 u$ M/ B" b0 |
有一个RasDial拨号函数的定义如下:
* {$ `2 a3 z& p4 s8 V: uDWORD RasDial(" s* o- b: h# o+ r0 m
LPRASDIALEXTENSIONS dialExtensions,
1 S! c1 _ b, C0 LLPTSTR phoneBookPath ,
- K6 G: c5 z) g* ELPRASDIALPARAMS rasDialParam , 3 d) i H; u" i: U8 f
DWORD NotifierType, . E* ]: R5 r O( O
LPVOID notifier,
6 b* d8 H% Q) c* i/ R3 ]" i' J: `LPHRASCONN pRasConn );
$ B$ ?1 z5 M0 Q9 u: Y, Q+ l! P9 G# j b, {
我的MSDN的解说如下:
+ x8 V% B5 ]8 s3 L. Z( S, dParameters
8 [# d, n% v( kdialExtensions : \" u0 N4 E% F. {9 ~) M
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
, E7 p% ]: q/ @" F* r9 zphoneBookPath / P! [6 i' Z; W# _
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.
2 Y4 O' z# X- Y; q6 t* \rasDialParam
3 `0 M% E- R6 q- r1 aPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
. H s+ g0 _ g" G2 jThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. . U3 f( d [& e* H. m- ?! u
9 m' G' ]8 @- t& D% q/ D* {NotifierType
$ j. X' c7 n) fSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: . U0 d4 a3 W+ L8 u) d- i& M
Value Description
1 u; a- b4 g6 g) w4 n- ]0xFFFFFFFF
8 n6 H4 A% a7 ]7 L! X0xFFFFFFFF 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.
0 p% K& I5 }; j. g/ M# w The progress notification message uses the WM_RASDIALEVENT message code. 7 K5 U% H7 ~( A
5 k: o8 V: U6 t3 j: N
4 k0 i; |3 F; J2 ~
8 q0 |9 B5 R0 r4 J
' d, c9 f' N! P3 Y onotifier 6 J. `0 v+ Y: ^& 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. ) w2 I2 a) V: k/ m! }# M6 v" L
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
1 g6 _2 m' l; h- b4 R+ z4 s6 A/ |
$ Y3 @. G, v( RIf 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:
; E9 o2 A2 l% e8 N* ?! P( l! K1 L
The connection is established. In other words, the RAS connection state is RASCS_Connected.
/ l7 {/ n( X. L' cThe connection fails. In other words, dwError is nonzero. ! F* N1 h0 m; u" f# {1 o
RasHangUp is called on the connection.
! r0 F) j. r9 y: b# e: yThe callback notifications are made in the context of a thread captured during the initial call to RasDial. 4 u+ ^2 b3 m% d2 v
* r# R0 l1 @& }& L& d* K; ^( NpRasConn & J# Z3 O% m2 f8 ~- d7 m
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. ( i: U% {# U7 v3 V
Return Values: t, K+ p/ d0 i. P+ r" 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. 2 d, S& p4 Z+ q5 `% A
9 `4 c2 @ a! D3 ~0 v1 A. H4 n
Include Raserror.h for definitions of the RAS error codes.8 {3 {% F' r3 e; T
+ {* h6 K% j3 d- q
Remarks! N( v* W, U8 Y1 V$ F
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL./ R4 f" C- f8 u1 x) i+ S# }) X1 V
- g3 ]# x8 B$ s' i$ g: v; d
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.3 I/ i" w8 c- S* w
7 z* G# A D8 }% d9 ~9 R0 I, iErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection. ( l; ]& w9 P- B- x. N7 S: I2 b- Y: K
. g) {# u. W/ m2 N6 o
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.
" q! ~1 x3 Y7 F$ q$ D. e
* P2 `+ G4 A* W9 w. jAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns. ) Q8 Q* G7 ~: o2 ~
- p4 u8 a, m, rThe 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.
& P. a/ E8 W( j5 i8 M1 Y1 S7 B: T6 x
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
1 z3 Z8 w, Y1 G* a# X% u k$ r9 fDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);+ l( J7 M+ L% v0 O
第五个参数是个回调函数,一般都定义如下:* Z6 B! j' A4 S4 j1 a) J5 Q
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)* D/ y1 ] I% }+ X) X
{" c- H5 I5 E+ r4 {+ n3 ^6 Q/ z# b+ ^
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
) I6 I8 j4 n( F; A( P; M
* t; d# o( ^& a _5 \, N) k RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
' Q' @8 H* Y$ v5 Z}' G& N7 G1 v$ Z4 V q4 O( K
这个回调函数将会把拨号的状态POST到各个窗口句柄。! ?8 i# }4 E+ Z2 l" K
* [2 `% ]4 y4 {4 r. N; i% K2 d
|
|