|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。% z, _4 w+ @* n2 V' E7 T4 X* [7 ?
有一个RasDial拨号函数的定义如下:) W% b' u; c: |+ _; p$ q0 y
DWORD RasDial(
9 \5 t u$ u' U* {7 R3 zLPRASDIALEXTENSIONS dialExtensions,
; q0 }1 x+ B% ^# |* Z9 g' Z2 jLPTSTR phoneBookPath ,
2 S- z6 b; P" v8 y) S$ tLPRASDIALPARAMS rasDialParam , - {3 k4 c8 q3 u$ q
DWORD NotifierType, $ D7 P! j8 B1 ?5 j
LPVOID notifier, 5 @' o( Z/ b0 r% d: h0 p9 `2 B$ v
LPHRASCONN pRasConn );+ a% L1 @ C: a" u6 M0 }/ r
# Z$ W" w! q/ C. N4 z2 g4 D我的MSDN的解说如下:
4 ]9 v+ R, x- R j0 d& FParameters" i1 U8 b x: V. c" t
dialExtensions
. p3 }/ ^) \" B/ QThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. ; }9 s' r) _( A0 ]6 @- _4 H
phoneBookPath
7 ~9 s. p' \, }: W( o4 V1 h( DThis 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.
M/ A7 x3 n. Q/ xrasDialParam - o1 A. Y6 ?0 K* K5 Q! ?) n8 }5 ~% q
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
- G& k2 D7 n' o, R* P4 vThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. 4 x7 g8 q' |% t
7 s/ X: R+ V4 [; l% H- p8 `9 LNotifierType
. z/ F6 T; h) O$ GSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
+ c2 ^! F9 z% C1 q+ L2 }2 pValue Description
% G7 P, w6 F' ^9 Y$ y+ z# E: I# J0xFFFFFFFF
" J' ?+ b* k( T/ r' O- U1 s3 b, j0xFFFFFFFF 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 Y. u1 ]# n, | ^4 o9 q2 D The progress notification message uses the WM_RASDIALEVENT message code.
% ~! x0 b& }- J M- k. t- N& x& ^
) p$ I; e) w+ m( L, n
* j3 \6 `: d6 U' e# T$ x2 k! J3 R9 h4 e3 C
' N' K, _ ]/ l& Rnotifier
0 }* X4 F2 S, I9 z" }; J, K! m+ xPointer 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. * _& k) d( v/ w8 a2 n0 |
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
+ w" H0 {2 R2 f, c @
! F0 T! V$ M" a4 x7 Z9 T( i; u5 VIf 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: 1 Z, r& P# {/ @( u
" m3 }$ D9 f0 O2 o: j+ w* uThe connection is established. In other words, the RAS connection state is RASCS_Connected.
8 C3 ~( a. I2 H* y6 u" vThe connection fails. In other words, dwError is nonzero. . j1 E! y. N$ N0 l- |0 p
RasHangUp is called on the connection. 6 K9 D) n m$ \7 \" |; H
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
* {' B+ n3 @+ i, @9 f( X) q: Y. v: r& h8 U, H
pRasConn
5 X: {' P/ N: w, RPointer 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.
( |" P2 y) |; p! ~ m% g3 ? lReturn Values
: U: z$ Q8 u' j, B1 TZero 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.
0 ~; e5 s- \4 ` ?3 |, U+ O0 o2 a# U9 P6 ?
Include Raserror.h for definitions of the RAS error codes." k% `5 k! T2 X e8 s. d
$ C' G2 ^% ]3 l' ]& T
Remarks/ M% _7 L ?* T
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.7 {5 |9 B0 I5 W1 h5 l0 u4 B; K
f9 g8 f# L6 s' `. [" @
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.* g6 a4 G! J4 C5 _6 s
4 H9 ?; c( x: C& \- R' @/ b
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.
/ s/ s4 W& G: ]( z1 [- n: q1 q% A% R; v2 e' J! E2 v0 u2 h
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. 3 B4 g: d V+ K! ]6 K
+ G _: o H: [# A! R! LAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns. . a7 G1 S3 v/ q" m' ?% J+ u
2 e c$ ]' c1 T5 b; G! e7 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.
2 x3 E0 a7 ]: P L4 p- Z/ O9 `6 w& Z
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号8 t; e* z) Q( h+ p/ K( @
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
) r2 A# z/ a* \0 S9 _2 L第五个参数是个回调函数,一般都定义如下:
8 e6 O* v0 p, xvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
8 t# I' t+ `% @1 a( R! _" r b* a{
6 o3 M6 T$ \( P' | CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;0 N+ r. J" J/ u1 b' Q
1 Q* y% d u8 E8 S" t, Q RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);8 {( I5 s& s( V0 _+ S. D
}
# G$ w x+ c+ s7 R这个回调函数将会把拨号的状态POST到各个窗口句柄。
7 J7 W1 s( d/ B+ ~3 G" H' _5 x3 B# C7 i
|
|