|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
+ o6 W4 C0 b+ L; X) F有一个RasDial拨号函数的定义如下:3 u5 L+ i, S$ R% H5 ]7 S
DWORD RasDial() W. G2 R4 i" R! W' ~
LPRASDIALEXTENSIONS dialExtensions, 9 R5 X' D. u5 r( i
LPTSTR phoneBookPath ,
3 E/ T- i/ S2 o' X" e, O OLPRASDIALPARAMS rasDialParam ,
6 X$ L6 Z% z$ C8 h$ s6 j3 g8 LDWORD NotifierType, 7 ^# \( A' Y6 U2 W$ H9 F" B
LPVOID notifier,
1 v* ]$ _( m# w0 d2 \LPHRASCONN pRasConn );5 E- h5 _2 \! y; c; g2 @+ Q9 H7 t% [2 y
) a3 j" q% S& M5 Y7 F+ s* l我的MSDN的解说如下: ], l4 V# W; ?! J7 y
Parameters
& g8 C& v4 z+ X, cdialExtensions $ _. Z1 `% @/ W
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 9 c% o( V F. y" A6 R' d1 e1 k7 _
phoneBookPath
% D& }5 A0 A: lThis 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. " Q3 K% }2 Q8 ~; v. n
rasDialParam * `5 x1 ?4 o4 j* Q) e
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. + S6 x4 {# J7 U. G
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
3 ?- L6 }$ X8 \2 g. i+ Z$ i& j$ E6 h* q
NotifierType
, N( ^: Y+ k% e/ M$ w8 |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:
/ ]% t* A+ b' N- K L* T* ]- _5 w2 PValue Description 5 p& H" D( W, x9 ]2 ^6 H; L- y
0xFFFFFFFF, R% X2 c" E& l8 q
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. 6 l( w! j, m8 |0 b4 V+ a: }
The progress notification message uses the WM_RASDIALEVENT message code.
! \' v/ j+ u# a0 \+ A& h% {, G2 J2 v) E" `+ U
3 U2 r {& x$ H' ^: h: h! _6 p- N
# Z7 k/ e$ ~4 S, \; p5 H/ X% f7 U9 U
: K" B5 ?/ ~% u( d: Qnotifier ) X! q& O& O' m. J" m8 }/ _$ T
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. ( y% ]) t: L" {0 N/ j* ~" f- L
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. % ^* l1 ]# f8 V, P- v9 }3 [
% Y! z5 A' t: C% S6 V& P
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:
3 Y8 n- d9 M0 _; ~0 _3 U7 g. u" f8 ] _6 m# y+ V( w+ M+ `0 {* ^
The connection is established. In other words, the RAS connection state is RASCS_Connected. 6 J+ ~# x) @" ~+ B6 I; s
The connection fails. In other words, dwError is nonzero. 2 I5 V. J6 T5 F1 L& M- t
RasHangUp is called on the connection.
$ B: }) r4 V, H2 u/ Q) oThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
) ^: x* q: p9 x# m5 C5 A+ h( Z- R' h: d, K! p2 e
pRasConn
% R8 x. o4 a; g5 y/ o' D! bPointer 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.
; f) c8 w& }: j) k l( TReturn Values
/ ^6 D2 X. @( Y2 C, m+ UZero 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.
& V# G, K- G3 I7 T
" N! @4 F4 r) oInclude Raserror.h for definitions of the RAS error codes.
$ b! f: V1 d' S* O) @! q7 ]
" Z7 Z9 b+ Y1 K6 o: ZRemarks
- S8 n# p* @' S# r0 s- WThe szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.# v2 m0 M9 f/ M0 o/ y" C9 ~1 N: x
- }+ i# o/ C. U1 t5 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.. G) T8 B1 {2 r
% n% N% j. q$ ]* \; I! sErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection.
9 W' C3 v& r5 ]0 q' u; m4 a, r) ^5 H( D6 U
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. # {4 Q- ~: ~- g# q c: c
- A, I' c" D% a+ R, G A
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. n! ?( H% R3 T# C2 y3 O
' s, F& G( K5 X" X
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.
7 `4 p1 \- }! r/ i. y& y
* \- U8 R# ^: M看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
' x( I5 p7 d4 KDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
$ f9 {3 B) Q& V, x第五个参数是个回调函数,一般都定义如下:$ g0 g3 J/ A# a! B
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
2 W8 b) u( Y4 Q3 C{
5 @( {9 L! Y) J: P' f6 p! j: L( T CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
. e q: f' e/ ]
" k- Q7 I p4 M RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
+ a; d, I/ F |4 |6 O) r) R( p& y}( `. ^+ m' Q- z) |7 `( h5 {4 X# y
这个回调函数将会把拨号的状态POST到各个窗口句柄。
: K: v6 F+ T% q: H2 V! n( M9 L2 }. h! `* j h: H8 m
|
|