RasEnumDevices

DWORD RasEnumDevices(
  _In_    LPRASDEVINFO lpRasDevInfo,
  _Inout_ LPDWORD      lpcb,
  _Out_   LPDWORD      lpcDevices
);

说明

枚举出所有可用于RAS连接的设备名称和类型。

参数

lpRasDevInfo [in]

指向一个用于接收设备信息的RASDEVINFO结构数组,每个结构代表一个设备。使用前应将第一个结构的dwSize设置为sizeof(RASDEVINFO)。

lpcb [in, out]

指向一个变量描述lpRasDevInfo参数指向的缓冲字节数。
作为输出参数时,该变量包含存储设备信息需要的缓冲字节数。

注意 为了计算存储设备信息需要的缓冲字节数,设置lpRasDevInfo=NULL,函数返回时将设置lpcb指向的变量为需要的字节数,同时返回ERROR_BUFFER_TOO_SMALL错误。

lpcDevices [out]

指向一个变量用于接收枚举到的设备数量。

返回值

成功时返回ERROR_SUCCESS。
失败时返回下列表格中的错误码之一或是来自Routing and Remote Access Error Codes或Winerror.h中定义的错误码。

含义
ERROR_BUFFER_TOO_SMALLlpRasDevInfo指向的缓冲长度不足。
ERROR_NOT_ENOUGH_MEMORY内存不足,内部操作分配内存失败。
ERROR_INVALID_PARAMETER参数lpcb或lpcDevices不能为NULL。
ERROR_INVALID_USER_BUFFERlpRasDevInfo指向的内存无效,dwSize的值不等于sizeof(RASDEVINFO)。

注意事项

以下示例代码枚举当前电脑中的RAS设备。
#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "raserror.h"
#pragma comment(lib, "rasapi32.lib")

DWORD __cdecl wmain(){

    DWORD dwCb = 0;
    DWORD dwRet = ERROR_SUCCESS;
    DWORD dwDevices = 0;
    LPRASDEVINFO lpRasDevInfo = NULL;

    // Call RasEnumDevices with lpRasDevInfo = NULL. dwCb is returned with the required buffer size and 
    // a return code of ERROR_BUFFER_TOO_SMALL
    dwRet = RasEnumDevices(lpRasDevInfo, &dwCb, &dwDevices);

    if (dwRet == ERROR_BUFFER_TOO_SMALL){
        // Allocate the memory needed for the array of RAS structure(s).
        lpRasDevInfo = (LPRASDEVINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
        if (lpRasDevInfo == NULL){
            wprintf(L"HeapAlloc failed!\n");
            return 0;
        }
        // The first RASDEVINFO structure in the array must contain the structure size
        lpRasDevInfo[0].dwSize = sizeof(RASDEVINFO);

        // Call RasEnumDevices to enumerate RAS devices
        dwRet = RasEnumDevices(lpRasDevInfo, &dwCb, &dwDevices);

        // If successful, print the names of the RAS devices
        if (ERROR_SUCCESS == dwRet){
            wprintf(L"The following RAS devices were found:\n");
            for (DWORD i = 0; i < dwDevices; i++){
                         wprintf(L"%s\n", lpRasDevInfo[i].szDeviceName);
                  }
        }
        //Deallocate memory for the connection buffer
        HeapFree(GetProcessHeap(), 0, lpRasDevInfo);
        lpRasDevInfo = NULL;
        return 0;
    }

    // There was either a problem with RAS or there are no RAS devices to enumerate    
    if(dwDevices >= 1){
        wprintf(L"The operation failed to acquire the buffer size.\n");
    }else{
        wprintf(L"There were no RAS devices found.\n");
    }

    return 0;
}

系统支持

客户端最小支持Windows 2000专业版
服务端最小支持Windows 2000 Server
HeaderRas.h
LibraryRasapi32.lib
DLLRasapi32.dll
Unicode和ANSi名称RasEnumDevicesW(Unicode)和(RasEnumDevicesA(ANSI)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值