|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
% G7 Q+ H% \6 \ ^8 Y" s有一个RasDial拨号函数的定义如下:
) C% M; u' F: Y& f3 kDWORD RasDial(
( \2 z. i6 p7 m. I# J- `LPRASDIALEXTENSIONS dialExtensions,
7 A5 N3 I. B' VLPTSTR phoneBookPath , 3 |- D% B4 y) K
LPRASDIALPARAMS rasDialParam ,
$ Y5 i( e5 d1 X/ v: v5 s$ UDWORD NotifierType,
t% L" m3 x0 i k0 PLPVOID notifier,
' q d( m9 ~' p# s% tLPHRASCONN pRasConn );9 }! l, l/ u. T6 @# I @
4 U% n4 G% Z" h) v) {' k( \4 Z我的MSDN的解说如下:0 m; C2 ^& H% t( h
Parameters( j; L/ @# h, m& s5 {; J
dialExtensions
5 j/ n1 x. K# i7 a3 @7 y2 UThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 3 l3 W" `* B' a* Z- j& S, h
phoneBookPath
$ W6 L$ s& i' O7 w C. T, S5 p: 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. # z7 A w- I7 D2 a' V2 ~$ q- o
rasDialParam % K% C# u: M! v% W g3 S
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. 3 k; D o! ^7 a; F, o/ K \. {
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. 1 E. x" E- E0 Y9 A+ Q
3 {3 C* h* B4 L
NotifierType ' j3 _$ Y. f0 w
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: 2 q( B6 r9 [ D' r
Value Description _! z2 P4 }. n" W3 U7 H6 I2 U( k
0xFFFFFFFF
' j6 q* }5 T# B0xFFFFFFFF 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. . h! ]. T* Q4 E0 ^: p( v: t# A1 f/ I
The progress notification message uses the WM_RASDIALEVENT message code. ; L3 o s1 t5 I' ~! M
4 x& d) f% p6 m' i# \) q1 g3 _( L+ R( r
. u7 G- M; F" q2 f2 Z, c
8 g. Y$ m; J* V lnotifier 6 @% [3 ]( B6 b) G0 B7 z8 X
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.
; C) M5 ?2 Q' I2 o- q4 E" a jIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. + l3 H v, K7 Y8 E: K7 d' R# D6 {1 e# F
* I$ E2 i& j. J3 A# cIf 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 t$ i4 X6 b: O5 H
: S8 c' i% E/ a8 g- t) z) R+ |, [- S$ OThe connection is established. In other words, the RAS connection state is RASCS_Connected. # v5 x( z5 B' r# G
The connection fails. In other words, dwError is nonzero.
1 u' w% Y4 _8 Z8 F7 b# K; DRasHangUp is called on the connection.
+ q& |3 `6 W1 b& i; ]The callback notifications are made in the context of a thread captured during the initial call to RasDial. 3 s7 L: x, u4 d
$ S7 H5 r8 k9 k( l9 n6 HpRasConn
, a# l1 |- n! I9 m* UPointer 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. ( t( f0 _, N! O; Y9 R
Return Values% g$ j- ]8 |2 m4 G: ~; U
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.
# N' Z/ u {8 r$ t5 q
8 s- U( i" C$ `Include Raserror.h for definitions of the RAS error codes.& z2 w& ~! z1 D6 {
& K" x/ p% E; _* ^. e! |& J8 P
Remarks' N, h0 ~" q$ `9 A% O' T3 ~: U% W
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
M: S% ? v6 @' P: V7 T1 C7 G5 S) J# _
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.! m7 V `+ }& ] {4 Z' m8 F
8 f1 V) P1 {$ z
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.
. l l: P( l9 h i" r
# h* }% V! x5 F; E8 M! uAn 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. ; b6 [1 u$ X+ K
2 }4 \# B) ?% s# R. {' Z$ @
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.
" y6 F3 g% W9 w6 E! e. F
k) {: I9 ?" Q8 S5 ]* r0 C1 w8 qThe 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.
9 y. K I4 U" `6 j' P6 U; C" _
) I% D7 `8 s* [3 S' E4 ^3 @/ [看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号6 O/ ?( o: ?) K# i
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);# H% ?+ J! Q7 q; J( ]
第五个参数是个回调函数,一般都定义如下:
. ^ S+ P: {: Y# O! jvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)) @, K5 V7 f }2 T3 R% l
{
7 Y9 }* M4 K1 [" ^$ z CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
/ m; f2 m1 U: R- J% [1 P7 l ' R( m# \0 D! v' t/ @7 J/ f0 i; g0 M) C
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
4 X8 _6 U& b* ~ G}# {! ^% f- i* D& K1 s z: Y2 h7 c. }
这个回调函数将会把拨号的状态POST到各个窗口句柄。
) ~% c+ S3 S! Q( x1 Y. ?
5 w/ v* d% h6 e/ X- J9 h0 A6 O |
|