|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
4 a7 b/ o+ O, i6 z5 c有一个RasDial拨号函数的定义如下:
' {* Q e4 H" W! V$ Y0 SDWORD RasDial(3 a7 D0 Q) p4 ^3 A8 G! L) `
LPRASDIALEXTENSIONS dialExtensions,
" Q" g H `7 E' P' P% @; `LPTSTR phoneBookPath ,
+ G* l! G$ w0 ]" wLPRASDIALPARAMS rasDialParam , . C% e. Q |- o A l9 H
DWORD NotifierType, & s( o8 A( s! ^. x
LPVOID notifier,
: U% b# i( X9 h' |+ i' h8 QLPHRASCONN pRasConn );9 t5 f( w' h# F( e9 M
+ N6 ^- Z& A) X6 f* ~
我的MSDN的解说如下:! }) E- o4 a' k) j6 v$ C& ?4 s3 [$ S
Parameters; W0 C- g. p; L. e3 k, o
dialExtensions
3 U: ?/ B `- c+ ~This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. / {% F/ [2 c# `; C
phoneBookPath
# c/ E/ D! _, k" C1 _8 P7 gThis 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.
0 ^* m7 {0 J$ w4 d" crasDialParam
. D+ {* ]5 a( S/ T+ zPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
3 }# v+ ~( X9 l0 {4 C& ^The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
% x2 }, Y3 m' l- z; X1 `
: `( s8 z! T( a# iNotifierType
, I2 P& P: I H, e1 E7 S* F7 ZSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
: T3 s. V ]9 W2 f. d! ~Value Description " }; _* [, b3 o9 M$ |( t
0xFFFFFFFF
X1 c' x+ F& X2 {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 Z, u8 Z2 U. n7 o
The progress notification message uses the WM_RASDIALEVENT message code. ! W& ~. y- ^/ h4 }+ x
" I; P a8 A _) O' S L
5 Y* y" S8 a$ f7 V) _- Y) d$ H
3 V# \7 z1 G! @1 s( M
- Q% ^# U( n$ k0 U1 P+ u' Q0 O2 t0 N
notifier 8 I5 D3 m# E c2 m: I
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.
- F) b4 P' n) @If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. \- F' R1 k: V9 m$ J0 R9 u" H
/ E) [1 J' B9 }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:
5 ^% ]' d1 \ n2 n/ j6 O3 x
( G$ c N5 a! u2 m& H2 vThe connection is established. In other words, the RAS connection state is RASCS_Connected. 6 A A, F0 k8 `& M) p1 x3 k- v
The connection fails. In other words, dwError is nonzero.
3 E+ r" \0 H6 p% t- Y2 |' kRasHangUp is called on the connection.
$ t( C* A& j2 T3 g1 T0 R# L8 bThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
: a7 ?& m A$ n0 K7 z; Y, v
2 z4 H3 l" z" J6 dpRasConn , ?) T) j6 j* |6 _
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.
" l# B# T$ g3 l8 K0 |3 ~. [" yReturn Values y8 ]2 I+ {8 S% d' s
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.
& W0 L# {. n2 L
( [; ^3 H" T1 VInclude Raserror.h for definitions of the RAS error codes.
4 r7 T; F9 w5 i9 u1 O2 Y, e( M7 V
% Q( t& k4 h' E) `. MRemarks# _/ d9 k( Q. G
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL., ?( U, O0 a3 K3 h
5 W- k6 |3 ]+ H2 I1 F }. Q+ U3 kRasDial 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.
: N) T* m) w. G# |, ~* E
' ]* n$ {% M4 }; n' hErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection.
' X; l9 u3 }: J# w: ?9 C* G
1 ]7 S! s3 u5 ]4 ^6 w9 V" EAn 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.
6 T8 t. ?, o x8 a& H
, M' w! o: z8 f# n0 q& k0 Q/ f# a& BAn application can safely call RasHangUp from a RasDial notifier handler. If this is done, however, the hangup does not occur until the routine returns.
" N6 C9 w9 I+ M! E8 ~/ h. C8 l+ e+ `6 W: h% @
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. + s+ W* Z, Q. I+ j- v
( @ [0 u5 F4 R. G( O/ V
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号7 [3 j2 Z% W1 ]3 _
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
$ w8 O+ r# a/ ~. ^6 K第五个参数是个回调函数,一般都定义如下:5 l, }7 X! C2 K, a) i+ n4 d( @
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
/ k7 y* A5 Z y{
1 Z" l( d; l, k- z1 A4 w" \ CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;* _0 i- J* d1 L: j' c% c& O
4 R& N U: y/ S [, a
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
4 E2 E6 c4 d$ `( \" V$ L: j}3 H6 ^. f( o4 t9 P- J
这个回调函数将会把拨号的状态POST到各个窗口句柄。
) q8 g# K. t# n
: H' s+ ~- D5 K0 s6 X5 Y |
|