|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。
& A1 | C3 K z9 ]8 s- r5 S0 }( Y1 u有一个RasDial拨号函数的定义如下:
4 i) v R8 P! p2 EDWORD RasDial(8 b& U/ ^' g1 c" H3 I0 Y
LPRASDIALEXTENSIONS dialExtensions,
+ r* z C& |0 Z9 c7 y8 j ]LPTSTR phoneBookPath , 6 O$ k/ g! }0 B; H) v3 ~2 H
LPRASDIALPARAMS rasDialParam ,
8 g9 ~- C* ~9 }3 I' Q$ ODWORD NotifierType,
9 [+ H3 s) O4 R+ w8 U) t9 }! |/ \8 ZLPVOID notifier,
5 {( r6 l8 u! }" _" e! L fLPHRASCONN pRasConn );! T6 Y+ ^+ j" D, Z% A& E: z
: F3 ? ]) F& O5 C
我的MSDN的解说如下:
9 G# J4 h. r; F, IParameters
1 ]7 y0 f+ ]( C* WdialExtensions + R; k7 ?$ I* G3 p; `
This parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options. & `5 R; `% x' G; e
phoneBookPath
6 `% |* @0 n- C) ~# F- tThis 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.
" T! K: t( ^& @7 ?6 E4 VrasDialParam + e' X) _7 E. J! G& I5 d
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
1 E( B7 \3 D2 p# DThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed. . i7 Y5 V2 C7 @+ r4 f
7 F ?3 i% t8 g$ u
NotifierType
1 w3 Q; S! `% Q( 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:
2 D. J2 W" |# q& GValue Description 7 O- t, m. ]$ @6 C6 s0 Z
0xFFFFFFFF
/ `8 y. I. I* S& P' T- E5 C- f$ G0xFFFFFFFF 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& u* y! w9 T) I( `8 G
The progress notification message uses the WM_RASDIALEVENT message code. / T" J) \1 v/ S
) c0 R4 O( q3 k4 @2 a' \5 q6 {
7 D/ t! Y a1 m s( w6 z& ]( g5 B% O
& n( c: B* E$ D2 R/ ?9 V
notifier % J! U2 a; O. M! u! Z& p5 Z1 O
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.
3 t; t) t; A! V: i( Q2 n) F' `4 FIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
% o+ b3 D, C6 v/ u! Z
% X7 V* Q. r& z( q2 `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:
+ n9 r+ @6 M- O/ _1 N* D t
f* K4 I* ?8 t P d3 k' FThe connection is established. In other words, the RAS connection state is RASCS_Connected. 5 i1 I6 h6 g @: y" L3 y
The connection fails. In other words, dwError is nonzero. 2 j& k' C- p2 T! D4 O" t8 O; b- J
RasHangUp is called on the connection.
; n, i! f$ R" wThe callback notifications are made in the context of a thread captured during the initial call to RasDial.
8 p" G! T- [2 h' Z6 J' M5 y: n" v8 b8 _$ f, W$ m6 L
pRasConn 7 `1 p6 U/ W. F, L, A
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.
# e: E' }# D) @ JReturn Values
# b" \! Q% K5 P- rZero 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. : m; ?* V! Y F h( j1 U& y) ^
, w& @2 j2 h" q5 U; Y7 QInclude Raserror.h for definitions of the RAS error codes.: e. A4 b2 @1 I+ H0 f
" P1 ]6 Z: w0 x2 U* n; r' URemarks& P5 T, v( T6 ]8 E
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.$ T5 \: P/ u) ~2 G3 R5 V, B, p
) ^+ |6 c, B% {8 s
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.' y+ s, R8 [& ?7 ~& h1 E. C
* W, G% F) q6 R# v
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.
3 _% } e: l3 b! ]$ S5 L k1 Z1 n0 `6 {" T
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.
5 y+ F; Y" ^! ]! s9 @4 t. q) U- ]/ x8 Q5 U2 @* K
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.
, G4 k! M$ ]4 p& V- w8 l; ]7 K! \
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. * D7 G( i& g( b: m; P
- V. [: ]; A/ ^5 P
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号$ I3 Y+ ? j" k) I
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);$ {7 O$ B" o8 n, _! L9 J
第五个参数是个回调函数,一般都定义如下:9 q# S' g7 d) b" _" L
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)- ]5 `1 Z% k* M" n$ c
{
& o I2 @' N* T1 l CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
% q# r4 ^" V, }4 _8 f' \
' X5 G' S% | m! Q4 `9 ^8 c RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
4 \3 o8 u: |/ b3 J}
+ U2 v1 }' |2 [这个回调函数将会把拨号的状态POST到各个窗口句柄。! q4 b& G" u0 S4 |! B9 T
* Y6 }9 |" x0 x8 @* u
|
|