|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
1 N* n( L _& O1 y4 R" U- q7 j8 c有一个RasDial拨号函数的定义如下:' x* h% y9 @ j; ^/ C7 m6 u
DWORD RasDial() q2 R d, y# S
LPRASDIALEXTENSIONS dialExtensions,
. I8 Z: L! d+ TLPTSTR phoneBookPath , # A' q' r! j' k: U0 U. R1 I
LPRASDIALPARAMS rasDialParam ,
8 {6 v! q' n J' q6 ]DWORD NotifierType,
) e- d# w! P3 b: ~- h ILPVOID notifier, , S) S2 ?, J* R6 I( n+ L) B+ L
LPHRASCONN pRasConn );$ n8 [* V3 S1 j8 x3 h7 i4 i- S
3 f8 `4 l# O$ A: F& U: h' M
我的MSDN的解说如下:
" e1 c% v- k$ g# p: G" ~Parameters
$ X. H) {" e% f% o. XdialExtensions
5 y3 I) O- Y- T, ~This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
V! Q! c, l4 K' f8 `phoneBookPath
( v( t( i; X1 @' |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. ' }& v& E7 x; C* v% p2 N
rasDialParam
% A! r0 E9 `+ O$ UPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
: t n) `* y8 j+ J; wThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. ) \' p) A( V `3 J) l" r' t
1 ]$ s0 Z! e8 XNotifierType
2 j* b* M M5 N6 u# C" \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: : J, Y( z( r$ |# c4 [7 ^+ _* u
Value Description
% M4 O' d, ?; }8 g0 P) A% w0xFFFFFFFF, n& |5 [* q9 X" g/ {
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.
, d! N3 e* I P7 Y( s4 i8 s/ p The progress notification message uses the WM_RASDIALEVENT message code. 2 x! I9 y% M% N& E4 s {) b0 w
1 B7 Z" [. R, H2 z% y
% ]% m* H- }* c8 J- W! _% x Z
& u- |5 i& k* z$ v" ?; R
9 S" T1 V7 U2 [2 h5 S: pnotifier
4 K8 `' p# B& s, T2 L* 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.
8 O, s# z& Y& @8 aIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
, W% g) U* I' l2 W3 }( r$ J- |, K* G
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: 0 u& I4 s0 i4 t- v& x$ K, u8 I
( e" B& R1 w9 E: _The connection is established. In other words, the RAS connection state is RASCS_Connected. ' z: c9 c O! a8 y) ?
The connection fails. In other words, dwError is nonzero. 8 f; k; i; r% [1 ~" K5 Y4 n
RasHangUp is called on the connection.
5 X( _0 `; |9 s+ w$ O/ @0 mThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
% a: Q9 |3 d+ x9 I+ _" z
3 A$ {7 Z) U: I" B4 K3 ^pRasConn
4 ?: n1 U2 c, M( G+ fPointer 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. 3 T0 o3 i- n6 I4 ^9 Y
Return Values7 `: r' P( [. F1 C' J5 G
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. 0 b9 x4 R3 a& l/ ^1 L) X
- B% r: Q( n6 P3 TInclude Raserror.h for definitions of the RAS error codes.
* J2 n8 j7 n) T4 B V3 C( h4 J* J+ \1 ?+ A8 \" l/ R; A
Remarks
9 r, S9 z2 l) q6 W0 Q& EThe szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.
5 |0 m9 ^& p1 m7 v
1 \: W! A# ?$ _4 K7 V' S2 WRasDial 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." K% w0 l" ~& S+ ^, f% a
& l* ^ F% h1 ~8 m$ R
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.
, R* v' z+ Q* Z7 Q8 h: f& R6 Y; D' i2 r4 n' _
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.
# E C6 X" K5 {3 }3 l' `( ^. U. M# w8 b# ?" r8 }
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.
7 a5 F5 D" z, x2 O# @9 {' y4 w8 }+ \. n
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. , S7 |3 }) i9 W! t( o
; w0 k; H- t B' B/ D) F看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
' \' p9 _& D* i" T9 @DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);+ {) z* X6 O- D8 V: r6 a5 C
第五个参数是个回调函数,一般都定义如下:
v5 f+ {- b% v- L+ o4 Z3 Lvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
' v; k4 v9 J. o: v1 n5 e7 I{
: C5 U! Y' r8 ?7 ]7 |$ W. Q CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
7 |6 C: N) U9 V! O* s" t 6 B7 \0 g/ {. Q9 Y3 c# V9 Z8 J
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
) Z, N' \/ X& Y}
: B9 e4 _7 M" m2 D& ^% i, `+ |. |$ ~这个回调函数将会把拨号的状态POST到各个窗口句柄。0 Y4 V3 b7 |7 s) c m
\& ^5 ]0 e1 w
|
|