该用户从未签到
|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。- k/ y$ ^, S- ^9 ^* V* \2 e
有一个RasDial拨号函数的定义如下:
8 q+ J' F+ C$ dDWORD RasDial(" ]5 m) T" P" ]$ B2 u- ]. B0 N2 u, S
LPRASDIALEXTENSIONS dialExtensions, * C0 |/ w! ~0 B
LPTSTR phoneBookPath , ) Z9 t/ O3 n1 |5 g! w9 p; a7 n
LPRASDIALPARAMS rasDialParam , ' N* h8 ~; g/ C7 ]& W& V0 e4 b
DWORD NotifierType,
0 q( u- v. [$ p7 ~9 rLPVOID notifier, ! I0 f) Y4 j9 }# B$ C9 o, d( U- h
LPHRASCONN pRasConn );. U. P, g( t3 `0 K
3 e9 _4 o! z& f
我的MSDN的解说如下:
* x- C: [! C* p; S8 E% n3 b9 jParameters8 T; Q; {' Q, _# X1 Z6 Y+ A
dialExtensions
$ @3 V' W: j, x. BThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
0 A6 v. ~0 I0 L! q5 MphoneBookPath
, n& Y; u% }5 d2 O2 C0 Q0 rThis 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. + o( {9 [7 N9 ]4 ?9 z( z3 `& @% g
rasDialParam " b8 T$ L% V3 ~' E7 ]
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
) B) Q6 P% }! I- s& N+ }% QThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
2 Q! y: P, e$ ~' c3 | G6 ^4 w
# ~7 A2 J/ B- L/ x# K& Z# I' BNotifierType & _: e! {: a" I- y A# G
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:
6 m; ?& M! G- B1 yValue Description
- A4 g, _, ^% @0xFFFFFFFF
- X* R* |! t' C9 B1 w0xFFFFFFFF 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. " o7 {" n+ p/ k- N; A1 _
The progress notification message uses the WM_RASDIALEVENT message code. # K& z, K8 B" x! @
3 x/ v2 @& e- S' g
) D6 {, M$ h+ o0 _6 _* |
9 m8 o2 \% ^( {0 u, N5 j6 U% q8 |( K1 Z2 T$ y8 ]( F. r6 {
notifier & e& S+ G" t2 N2 j9 l
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.
. G* l- W9 N1 S5 [) |! d) \If notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed. $ E$ C4 w( k, x8 i' [" j u7 }( M
* O0 a. W! j% u! R6 U
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: % M8 l- z) v/ Q; x
/ k9 c! a- @& ^5 ], L
The connection is established. In other words, the RAS connection state is RASCS_Connected. 0 ?9 Z8 ]4 w$ D; h) j% P; ~6 `% W7 g
The connection fails. In other words, dwError is nonzero. ) n; f; o! Y9 E3 C' I
RasHangUp is called on the connection. ( M# I: m1 n4 _4 L9 V6 w
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
7 r. {# A% \& \: u, z' g% U
0 S* t% u2 g* ~pRasConn ( s& _' n2 Q0 z7 C7 m2 R4 p' N
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. 4 W* S: w5 v3 }$ \
Return Values
* Q+ C" j- {9 E( K; J# OZero 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.
7 u' a; }! @4 u5 M9 E2 L
( }1 O: J' p/ {* C! KInclude Raserror.h for definitions of the RAS error codes.
% c. ?& x3 v9 D% a+ C# m- ^) `2 Z" m- P8 a# N4 x' N
Remarks5 |! g7 I* M7 z$ t- W4 F9 I% @! \
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.# T/ j+ o I/ E: l! _
) S: F# U# I V
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.% N/ q, j0 j% i a
# f* P7 }/ z& M" F: k" D ^
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. 2 B7 l/ g( ]4 U4 s2 k" u
6 ?- ^6 Y0 P. i9 q) KAn 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. 4 [5 s* Y5 `" f+ ~7 |. ]8 a1 {
2 g, ~8 ?; n9 i8 }& h- @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. 9 I3 K9 d5 Q! c/ Q) L: g) [7 e
; a% {5 W! Q3 u9 |. T5 ?( ^; _# kThe 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.
( F8 G$ O0 C& {* o0 s5 W3 [
# } Z. Z/ q* ^7 n看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号1 P9 h% S' h) C3 s7 Y
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);6 }, W e( {' Q1 k9 R
第五个参数是个回调函数,一般都定义如下:
# x/ g( i' M5 Y9 k7 q' m; W: B1 |void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)9 @$ f# y( n# E! i
{
5 K. z ~+ v% O1 ~) C4 r: R CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
" \* X' Z! p( V% ~. J/ t 3 K3 F* P; C1 [
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);
% O* `7 l0 \$ q/ G( ^8 r}6 I" M- M# N6 h
这个回调函数将会把拨号的状态POST到各个窗口句柄。8 q) x0 E1 }" P L
9 M) ?$ R+ n! K- h |
|