|
6楼
楼主 |
发表于 2003-10-25 00:48:00
|
只看该作者
谢谢周老师,不过这个问题我自己查了将近一个月的MSDN,终于搞定了。. i0 j, Q% }% m* ^
有一个RasDial拨号函数的定义如下:
0 W3 z, j9 e p$ ~: MDWORD RasDial(6 I+ a! J; F6 t6 P% ]
LPRASDIALEXTENSIONS dialExtensions, " y3 m/ ^# Q) [1 v
LPTSTR phoneBookPath , 5 E6 N& M* x( | G& u- a5 y
LPRASDIALPARAMS rasDialParam , 8 b6 u( r. n2 g
DWORD NotifierType,
; l* x, O/ `2 U% T+ b: v, FLPVOID notifier,
2 g2 Q7 P5 s2 r- K9 O( {" G1 PLPHRASCONN pRasConn );. s& T* O7 j8 F/ W) y$ E2 ^( b
& V5 l* z. L# v9 {0 N) Y7 `( D( Z我的MSDN的解说如下:
, l2 G* j% U* j/ B& ~5 c2 j/ dParameters
6 r( b+ T. a3 @9 `dialExtensions
0 o5 [( o7 ~* l3 D+ h% R- f4 G( eThis parameter is ignored and should be set to NULL. On Windows CE, RasDial always uses the default behaviors for the RASDIALEXTENSIONS options.
( L) r$ f- R. E2 lphoneBookPath $ D ^1 O: I- @. ]5 _
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. ; h1 K2 L, u/ I! s, [/ E9 ]% @
rasDialParam 5 I' o; u i4 |) z
Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection. + w4 w) Z- C, R# z1 w: O( J. w
The caller must set the RASDIALPARAMS structure’s dwSize member to the sizeof(RASDIALPARAMS) to identify the version of the structure being passed.
' _8 }1 @. B9 g S! ]' E4 }' V4 Y3 r n# L
NotifierType
3 M% S* J: _7 T# }6 q6 e/ U5 l hSpecifies the nature of the notifier parameter. If notifier is NULL, NotifierType is ignored. If notifier is not NULL, set NotifierType to the following value: ( P7 S% Y- Q5 _7 ^1 o9 y
Value Description 5 {! Z% v `; @
0xFFFFFFFF
- R7 m& s1 Q6 W6 v- {' k0xFFFFFFFF 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.
) X& y5 [# y1 C6 ^ The progress notification message uses the WM_RASDIALEVENT message code. 9 X/ j) M a Q
. E& w7 s( ^' r7 \1 U" W/ q8 h- p
3 ^% M) h# c# z1 {, f
/ H6 P* o) v$ [- E/ h3 P5 E9 @$ g; a7 m' Y* ~8 x
notifier 0 u: z* _) V" b- m3 c
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.
+ d; U1 f1 o% V' P7 L9 w$ Q: NIf notifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.
X. ~ n- k% \6 p' J* N
- Z3 d5 @ r0 ^, M9 o) lIf 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: + f! {6 y7 U9 a( u
2 G" n1 m1 S/ N. S+ [
The connection is established. In other words, the RAS connection state is RASCS_Connected. - n, Q, e4 Y& x1 S. `% W& H) F
The connection fails. In other words, dwError is nonzero. ) ~) P+ q T. P' a
RasHangUp is called on the connection. 9 H. R3 b" M3 J. W- W0 Q3 ~" b
The callback notifications are made in the context of a thread captured during the initial call to RasDial.
2 M( @4 J, P& Y
! N" H7 h$ u& u/ _. xpRasConn
% b: E& L3 {, k7 m- g6 {7 y; yPointer 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. $ \) x0 J5 C" S8 ?6 F0 M- x
Return Values
: W) D! ?( M" {& D8 U/ ~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.
- d# w( _! I2 X6 s7 U+ f$ U' J. s7 s5 | Y! [
Include Raserror.h for definitions of the RAS error codes.5 x5 p6 ?% D" r
+ V3 C6 U# O; q& t/ q
Remarks
$ H0 h' n) Q/ `The szCallBackNumber and szPhoneNumber members of the structure pointed to by rasDialParam are not used and should be set to NULL.7 H+ R# g0 D- W3 c! Q, }$ ]
+ a/ c6 @* F% v, A3 C* Z J! d6 j, F' iRasDial 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.
- L" P$ l( `% e/ Q
# d, l$ } r3 L7 GErrors that occur after the immediate return can be detected by RasGetConnectStatus. Data is available until an application calls RasHangUp to hang up the connection.
* V) w6 L: q1 \- M
$ T; Z5 ]: N$ Q$ H7 z3 u" F8 jAn 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. 3 s( v* i5 @" g) ~- v3 q3 v8 ]
" f9 q& C* k7 D5 l8 t+ L/ t8 G. 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.
4 h. \$ I7 B" ]% [' x a1 i( `0 @7 j4 j, ]- }# f
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.
/ q/ q3 j* k. b+ m4 P+ q" w4 g6 R1 W* |9 X& @) r% o' A
看了好久才算是略略通了一点,要实现我原先预期的效果,首先要用RasDial函数进行拨号" _2 X i: }: e4 X7 J
DWORD dwRet = RasDial(NULL, NULL, &RasDialParams, 0L, (RASDIALFUNC)RasDialFunc, &hRasConn);' v& K0 b: D4 ?. @# J
第五个参数是个回调函数,一般都定义如下:& Z8 R) P, p& [" Z
void WINAPI CDialerDlg::RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)% Y5 j. p h) h3 E) K
{+ N& c7 L! h( C: J/ c% [
CDialerDlg * RasDlg = (CDialerDlg*)AfxGetApp()->m_pMainWnd;
2 e6 K" i% M3 ^5 S0 u 7 |# r4 Z8 B, e0 u$ h$ U' g
RasDlg->ostMessage(WM_RASDIALEVENT,(WPARAM)rasconnstate,(LPARAM)dwError);: g9 _8 s9 _# f. V9 i: O. K
}* V* d3 @& O# {' z$ Y$ f- P
这个回调函数将会把拨号的状态POST到各个窗口句柄。
, M2 J* V; H, {0 l4 d( S0 f1 B
& ~; k& i/ r$ x! O7 }* E |
|