|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
4 w7 X$ G# r9 P. }有一个RasDial拨号函数的定义如下:
3 P s/ n6 O! D. pDWORD RasDial(
3 H# d N% ^8 b/ m* t& b( dLPRASDIALEXTENSIONS dialExtensions,
) Z' i( D9 L/ s x& H" L2 ~LPTSTR phoneBookPath ,
! Z: n' S% y; @% KLPRASDIALPARAMS rasDialParam , / m, U$ H) M. S6 M6 P
DWORD NotifierType,
8 g6 e9 w. V0 ALPVOID notifier, 0 b S5 R( [0 B9 i
LPHRASCONN pRasConn );
/ O- ]9 d8 @" q; j" _8 X
9 _6 N! M, e* L* R我的MSDN的解说如下:- y+ M" P, ~% v" T( ?5 l
Parameters
" @) T- W" u2 ^4 Y1 S) H& VdialExtensions 7 \8 a) _; f+ @
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
+ b( A0 g6 w) i& ZphoneBookPath
$ R5 Y( p9 ` b, 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. 7 _7 y( M; d. ~0 u7 g
rasDialParam
# _4 K3 E! Z$ d1 l+ U3 RPointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. 1 c X. N: C- X, G
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
2 ?+ S7 Z' [' a& w! ?, t0 u8 t) W5 q0 M# a$ ~
NotifierType
) d- ] h% Z3 D; P% o, U4 RSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
. z1 B! ~! M. e6 pValue Description 5 @4 F$ z( n* v7 I2 a/ N* o/ k) y
0xFFFFFFFF
- M0 ~7 x0 z9 X6 F8 k* l' s0xFFFFFFFF 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.
) T) o: ]- z& u4 x% }& S# _ The progress notification message uses the WM_RASDIALEVENT message code. - R( J( @+ }8 h; S
& B3 K9 w/ `" u( @3 d; c
1 L) c! N( H' L& e) U7 s* |/ a
; h) L9 g8 K) B+ N. P/ {' w& h% @$ E+ y$ P8 B6 W& e, O: F
notifier
: O5 Q! ]4 Q) F9 Y# E6 K9 DPointer 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.
" \7 ~. e! N; G* nIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
3 G2 ^3 \2 O% _! s( \
8 Z6 W& ?9 X+ ?* X# g0 FIf 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! n; W+ C' M% F
% c8 y$ B. U+ y& }5 W7 A. ^2 sThe connection is established. In other words, the RAS connection state is RASCS_Connected. $ ?! d9 Q7 F6 J$ w; _. [3 H
The connection fails. In other words, dwError is nonzero.
" P# P; }% W o# E* \% _& xRasHangUp is called on the connection.
6 w2 W4 h+ A; o3 w, JThe callback notifications are made in the context of a thread captured during the initial call to RasDial. / s; y% w w: c! r- J$ E
# C0 Q% l' Y9 d6 K- P( l
pRasConn % z7 M9 s5 n& p/ K! H
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.
3 }9 i( ~; {6 \% c/ D6 g( L! uReturn Values! K5 ^7 Y% y. p8 b. J
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.
& g/ \, c# F0 N# |( a. L" ^* Z
! d% H7 J, @4 R- G4 cInclude Raserror.h for definitions of the RAS error codes.& y5 F% i) O2 M0 x7 } V
% J) E( w1 w' _9 C9 h' pRemarks ]% m% B' ~" \9 S6 Q
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.& q9 O; g5 u8 }8 x$ D+ ?: _
3 c9 b0 c+ T6 q/ b9 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.
* @1 U7 \5 T; v1 {% `" J# N0 |* t! z0 t5 L( @# 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.
" b1 d' {! A9 U. | U
2 [% ?& ^' K% ^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. ! V* |8 v" _1 d0 E6 Y$ J
: E4 e' Q; r$ X# X5 \3 L0 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.
5 @. {& ^ E# D, c0 r! F; Z
G; `, p# G" DThe 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.
! [) _% u% l: g5 ]
! w, @- s. x* z/ X$ L看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
, M# P1 F8 s6 u, {& ]2 jDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);
2 k) ?! q: L& ~; `2 w9 l/ \第五个参数是个回调函数,一般都定义如下:$ R- t2 `; K% w* C+ q5 u4 ?
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError) n" D5 K$ F- J8 E; g
{- F4 e* o7 q7 r$ Q5 r( C
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;: p; h; V& w5 c1 w9 Q. s0 j
; G* A" g; a- L- L; ]
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
8 x4 E2 q5 i9 D" p' P( c% y$ e}
/ I' w; l# _$ R, i# P这个回调函数将会把拨号的状态POST到各个窗口句柄。 H+ ?% R5 d- f
& a7 g4 H1 Y/ L/ T& m; w4 V8 Q |
|