该用户从未签到
|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。: t5 {' O. L; X0 _
有一个RasDial拨号函数的定义如下:
& M4 ^ {) M" U1 x, ]. _DWORD RasDial(* h8 d6 e( ^4 U& S9 L( ^
LPRASDIALEXTENSIONS dialExtensions,
/ s" q+ M; q7 H( G1 i! nLPTSTR phoneBookPath ,
6 [" g; Q7 Q# o4 S: D, z; r( wLPRASDIALPARAMS rasDialParam , B ?; x6 l( Y4 q9 s
DWORD NotifierType,
* A0 P3 l0 B5 [4 |9 K1 ^LPVOID notifier,
' q; O3 z5 E/ hLPHRASCONN pRasConn );: n/ Y, X! q( _, Z U4 c, ?' _
3 X, D n, s4 k2 l
我的MSDN的解说如下:3 E6 C' a1 r1 e' v! P: h
Parameters
& Z1 T4 {( W7 H% N; u9 @dialExtensions * L" l4 ^8 `6 l% r7 o) B
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 6 c$ r0 ]: I% E( Z+ |% A! q% ~
phoneBookPath
" J5 G3 U L; H& q$ E+ QThis 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. . b. E; n! ]$ s
rasDialParam
$ {; K5 R8 o; R7 V' s- B% M% L0 pPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. / V6 y# i4 V& P: l
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. : V, ]# n/ a& Z; M& q% Q9 ?' e1 j
: b3 f3 P. v' Y/ k/ n- iNotifierType
- U- O6 W# u% ?0 z$ Y% pSpecifies 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; s* i4 q" P5 h# R
Value Description
( \/ e- n7 u; J! k0xFFFFFFFF6 \* W7 Q+ P! u( n2 J% L
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. 1 V# m) h- y2 o$ C' ]3 n
The progress notification message uses the WM_RASDIALEVENT message code. ' }' S" u3 @9 n
, X5 v! b- L& B G+ h! h- a
0 w9 F- R1 a7 S W8 D4 V
7 j+ `' P+ e7 } M% p
5 @# \( X* U" qnotifier
' w. x. Z% d& V7 \# V; S- m& LPointer 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.
1 H! y0 l: V1 S e" W" F$ XIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
1 f8 J& ^+ l! v! j' n. r0 S% {8 s# t) c$ b4 |) c! z# p1 U& X* w1 e& W! F- \
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:
% S# s6 j( ]3 m' ~7 t% h1 |: Z5 j+ U
The connection is established. In other words, the RAS connection state is RASCS_Connected. ; x: P5 l2 I1 \4 L0 f! X& \
The connection fails. In other words, dwError is nonzero. 9 K3 p; Q i0 V9 C, \% A; G
RasHangUp is called on the connection.
_. V9 I1 D( R. H+ S3 uThe callback notifications are made in the context of a thread captured during the initial call to RasDial. , |" L' r9 C$ k4 a4 x& }! O6 U
K" L9 t* n: \# i5 m5 Y {pRasConn * v* Q( \3 P! h _8 {- r2 V; d
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.
+ V, V4 n& F+ P) V, X. o# ^1 fReturn Values
) w, M$ L" a+ _+ e. t* E6 D# N. JZero 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.
) A: C1 g2 Y: P" y( Z0 Q4 }) O0 S+ Q* |4 f
Include Raserror.h for definitions of the RAS error codes.( t* H" U; S v7 o& B
5 ?% ]$ m3 h, N# C) E. e8 l% C3 C5 ?Remarks4 v7 ?, I# S9 r" k3 s
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
5 C; J; X+ v, _4 P& ?+ g0 x, S: M
% D' M6 ^' C1 T- e; d7 g0 b1 `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.: P; U3 q0 ?( h9 F, ?. i* r
5 X1 n4 o+ \( U
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.
0 |; X' H" A8 a) G1 M
0 H+ a( i% _3 W6 f3 r& FAn 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.
! v* ]. N' X- W7 ?& j, H6 U
7 I e- l: j6 w8 B5 o2 ^1 h, ~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. " k/ P* k0 Z b/ \
: z( H" g7 }2 G' d2 z
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. # E9 `6 C9 D# j: c7 b
1 P5 s9 S& |5 W
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
8 W+ i( u# A+ z3 H* oDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);2 D! a* _) [/ H8 Q$ G$ V
第五个参数是个回调函数,一般都定义如下:
; c8 E2 _$ u/ N; \/ o+ Qvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)* L, o+ G N& b+ K0 X$ ^1 Y0 @
{9 D4 ]6 h" T, n8 f: c( g/ E# E
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;9 w7 @- h) \: I- R* N
/ ^: R; J; _! ^* Q1 T RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
3 q, i: X+ L. V( [. v9 R}, H! ^* J5 x8 ^; X6 {; D
这个回调函数将会把拨号的状态POST到各个窗口句柄。
$ U) M: `# [+ w8 q$ U* I2 s0 M& y. j& X$ S
|
|