该用户从未签到
|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。/ e3 I+ _# K9 u/ C4 O- ^* `4 N
有一个RasDial拨号函数的定义如下:
, h. T* r8 J0 b1 x" }DWORD RasDial(
- S& i3 [; z: u' p( q3 g. i- ?LPRASDIALEXTENSIONS dialExtensions,
0 O7 {- q1 f) R q1 dLPTSTR phoneBookPath ,
: D1 D0 [7 f" \9 m7 Y% JLPRASDIALPARAMS rasDialParam ,
9 q6 j- K( X7 YDWORD NotifierType,
! e( O _7 O" D BLPVOID notifier, 8 L( B4 t& q/ q* o5 T/ R! P# x
LPHRASCONN pRasConn );
5 v" W m) X; K% Q j# E$ t. r9 v# a6 k3 O+ |1 j7 @1 I
我的MSDN的解说如下:
9 ] Y: T- P2 _Parameters* ~6 p' x6 z% y$ ? |5 Z
dialExtensions
6 N/ m' W. B+ h; C: HThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
. c8 r0 Z/ _6 U d3 N. [ k# NphoneBookPath ; |1 W' W( K/ ^" H9 n
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. + \' r/ ^+ R* f, C3 D& N! N% v
rasDialParam
% ^, o! V2 t( `Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
' C% u) Y/ p6 [ oThe caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
( @& W1 v& L( i/ x/ u" u! r" O+ P, P
NotifierType
. n9 h/ x! y0 u8 P2 ]3 MSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value:
' a1 k, v+ d: Y3 V: r8 ]" XValue Description
{8 Y2 i o5 A0xFFFFFFFF
* R4 j) z' w* |8 E) 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.
) V) v1 D7 P: Q8 w9 q- Z The progress notification message uses the WM_RASDIALEVENT message code.
" T; y% i# c) g0 x H' @9 p) v$ R4 J8 t7 u
/ B$ _/ A0 P- G$ z+ `1 R. B
0 G1 n" N$ J. ~- I# c2 W
0 N. g0 y* V4 G6 l) Enotifier 5 Y' [7 \, w8 P5 y4 `
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.
+ c4 H+ V3 ^9 qIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
# B) i/ X% U5 j7 `% b2 @0 r% U6 l) K+ ~3 y/ l* L$ g& G, q
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:
+ ?* t3 M+ v& e$ K) d0 G2 D: u4 C4 ?5 G
The connection is established. In other words, the RAS connection state is RASCS_Connected. ' I( _- O! d* i8 b1 Z5 s
The connection fails. In other words, dwError is nonzero.
0 m1 S5 s* y2 ~RasHangUp is called on the connection. , V5 t# u) I7 h. W! R
The callback notifications are made in the context of a thread captured during the initial call to RasDial. 9 u/ e, x6 ]: u; Y
( f9 v V j) B: y+ _pRasConn $ H7 A+ @/ z0 I- m
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. 6 W& f; d( ^6 R% f
Return Values
( p: R' `$ f- \ P! b+ NZero 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.
`$ l3 I5 b; z4 E _ ~$ w1 m. p, b4 A
Include Raserror.h for definitions of the RAS error codes.% c3 @1 y" Z% z/ t
) ] D& h6 ~- L7 \4 p3 |$ ~Remarks5 f t+ @: U' `9 f& a7 E: ^
The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.1 {: {6 ^4 ]0 d1 o8 K
0 B0 l5 q$ V/ a8 g- R: ZRasDial 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.
: v" Y; @5 c9 p3 J- h) t) ^, B$ F% I8 F8 ^) 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.
9 j2 |) p1 }, y3 b d: T& T$ w7 C- E3 F& X, R7 F
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. - X% b7 c; V! r g
' ?! o7 E1 _% u9 ^4 t8 A& S% U
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. . R2 X/ H/ T* T! L. V; i/ i
% N0 Y& p: h) pThe 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. . D' |. ^* |8 d- \
( \4 ] ~0 R! k7 S- X
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号
! k8 | I# w$ f, GDWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);. g2 u1 J4 W( N9 @ h/ ]5 Y
第五个参数是个回调函数,一般都定义如下:
& v/ T6 ?2 R5 r4 Fvoid WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)
1 y5 [& b o, Q; q3 |3 w! w{ h* A% l4 S: |' g2 L/ t
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;! H* c3 G4 t, P* A
N0 M' s+ F T3 r RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);$ z5 ]! E" ?9 ]
}
8 v4 f, Q/ d X: I这个回调函数将会把拨号的状态POST到各个窗口句柄。
. A4 X, O7 z# ^2 O0 B1 J4 K1 g4 X" |3 J
|
|