#include "stdafx.h"
#include <windows.h>
#include <ras.h>
#include <rasError.h>
#pragma comment(lib,"rasapi32.lib")
//一段自动断开adsl的例子
int _tmain(int argc, _TCHAR* argv[])
{ DWORD   dwConnections; 
RASCONN   rasconn; 
DWORD   dwSize;
DWORD   dwSuccess;  rasconn.dwSize = sizeof(RASCONN); 
dwSize = rasconn.dwSize; 
dwSuccess = RasEnumConnections(&rasconn,&dwSize,&dwConnections); 
         //dwConnections总是返回0,在vc6.0下面就返回1
if(dwSuccess==0) 

if(dwConnections) 

RasHangUp(rasconn.hrasconn); 

} return 0;
}

解决方案 »

  1.   

    本帖最后由 happyparrot 于 2010-12-06 21:17:25 编辑
      

  2.   

    RasEnumConnections 找到当前活动的连接代码原封不动在vc6.0可以找一个,成功断开当前连接到vs2008下就找不到了
      

  3.   

    使用范例:   //下面建立了10个RAS连接   RASCONN rasCon[10];   rasCon[0].dwSize=sizeof(RASCONN);   DWORD dwSize;   dwSize=sizeof(RASCONN)*10;   DWORD dwConNum=0;   RasEnumConnections(rasCon,&dwSize,&dwConNum); 
    你多建几个呢?
    RasEnumConnections的返回值是0??
      

  4.   


    看看函数调用成功了没?GetLastError()
      

  5.   

    RasEnumConnections返回值不是零dwConNum返回是零
      

  6.   

    那就GetLastError看一下错误原因啊
      

  7.   

    终于好了,把0x0600改成0x0400就执行了,adsl可以成功断开
    但是不知道为什么要这么改#ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0400//默认是0x0600,不通过
    #endif#include "stdafx.h"
    #include <windows.h>
    #include <Ras.h>
    #include <raserror.h>
    #pragma comment(lib,"rasapi32.lib")
    int _tmain(int argc, _TCHAR* argv[])
    {
    RASCONN rasCon[10];
    rasCon[0].dwSize=sizeof(RASCONN);
    DWORD dwSize;
    dwSize=sizeof(RASCONN)*10;
    DWORD dwConNum=0;
    RasEnumConnections(rasCon,&dwSize,&dwConNum);
    for(int i=0;i<dwConNum;i++)
    {
    DWORD dwRul=::RasHangUp(rasCon[i].hrasconn);
    }
    return 0;
    }