|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。+ I4 a0 D8 g/ J: U5 s3 ^8 A
有一个RasDial拨号函数的定义如下:8 Z; I9 ~5 I. f8 O2 y
DWORD RasDial(- C8 ~0 d f* k- e
LPRASDIALEXTENSIONS dialExtensions,
! b m' N5 J, B8 ]LPTSTR phoneBookPath , : g0 p& m( Q0 O
LPRASDIALPARAMS rasDialParam , 6 A% X& ` N7 v m" ?0 m: l
DWORD NotifierType,
% @& j* G1 D8 J, n& ULPVOID notifier, , x+ [8 p6 @: ~2 T" y2 S
LPHRASCONN pRasConn );
# `! }) S: z2 U' h" U7 R7 ]! e+ Q& w* _& W- J/ J
我的MSDN的解说如下:. B4 p2 e! a9 ?& ^
Parameters5 [5 m- L, `8 V$ u$ \/ k5 S
dialExtensions 9 F2 a1 }0 v$ h% C0 T$ N% @
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. 0 D5 ^" u% Y: r0 d, U( @/ j
phoneBookPath 7 T {. c7 k/ r j
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.
" v2 y& v" o' n. `7 MrasDialParam , g" P1 J9 s- ]" `+ X% Y
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
4 o9 W J+ d9 ^5 Q3 T0 i O: nThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. / [& D4 a6 B9 q `4 V" l
7 V M6 `7 B% ]5 N& u7 J7 ~ j
NotifierType * B) g4 a# `: J8 {
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: : ]4 n& N# Q9 _! _ B# g
Value Description . ?1 M# d* C4 v) E
0xFFFFFFFF
2 ]4 Z+ [2 c* w6 w% Y3 r* E! q0xFFFFFFFF 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. : p$ v+ V+ |7 K2 K- a% Z! Q
The progress notification message uses the WM_RASDIALEVENT message code.
+ F7 G; [9 I) i% W* j/ U" @% O0 s0 \1 W
/ [7 E, a% S- L- z9 H2 K
" j8 u) J2 t& D' y0 D5 M; i8 r- s# O5 Y, H; E {) G
notifier 8 o1 }6 z; y* v) B
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. 0 t9 H! O9 N9 f- f
If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. 1 W4 H$ O! h$ |
! D7 m& v7 \/ Q" G9 i, d! P+ n
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: ) c) }3 V/ c9 r: m/ n: s
% M6 s4 t& k, r7 Z% H* j4 K9 i
The connection is established. In other words, the RAS connection state is RASCS_Connected. ( X. M' W* D4 h- J
The connection fails. In other words, dwError is nonzero. + r! ^0 r b) e& l5 O" P$ E; v' f2 i
RasHangUp is called on the connection. $ |! [; f& | i+ \: R
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
4 @5 u6 C0 B0 p7 F7 F" h# L, j4 b4 t% y* j% R/ U
pRasConn 0 E3 W. B; x2 { w1 ^, W: ^
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.
/ B8 O9 I% @2 pReturn Values
{! U& v" h! D$ q3 AZero 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.
3 u4 L% z2 | M S9 ^- D( {- o# ` b( t9 g. w# ]) l
Include Raserror.h for definitions of the RAS error codes. `! l4 Z) R2 y5 q
2 N: [ j* \* @, B
Remarks" Q+ z* s& B; p1 U4 y/ Z$ k: R
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.* T: R6 l; N1 l4 V
7 e Z" q8 j/ t/ i: ^* d( O+ ZRasDial 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 r, f( }8 |2 V* B' D
; c0 Y4 n, M6 g* k" `/ W5 p: I
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' d, ^: ^. u- E; P' F) q
# a/ M y* ~- f6 q* ]7 R( ^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.
' _. A3 X% r5 y+ ]/ P, P, t. i7 }, ^/ ]5 S3 J) f
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. 2 c' n# J, A7 G2 X8 P/ d5 L
- R" w/ \/ a. H5 k# EThe 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.
% R% s% V! u% g8 ^, ]+ J Q }) q6 r9 e( F3 {1 z
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号' Y: @: _( r+ M& `2 O+ u
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
2 `0 n" j; Y) v7 X" W4 N s' g" @第五个参数是个回调函数,一般都定义如下:
( P. H; o# x6 k% g0 b0 qvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
+ }' D) Z4 Q) ~" b{ \# c+ O$ M# E# E. |: N# c
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;1 \9 L! B$ k2 j7 Q
% e* i* S) S2 X5 d% U
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);& P. V9 _; _/ U2 j5 @% F
}. K0 B0 K) C" F2 a
这个回调函数将会把拨号的状态POST到各个窗口句柄。
, \0 S, ?8 c9 P, R4 [/ O* Q3 @9 D n. R* I; Z# l( H) T
|
|