RasEnumAutodialAddressesA 函数 (ras.h)
RasEnumAutodialAddresses 函数返回 AutoDial 映射数据库中所有地址的列表。
语法
DWORD RasEnumAutodialAddressesA(
[in, out] LPSTR *lppRasAutodialAddresses,
[in, out] LPDWORD lpdwcbRasAutodialAddresses,
[out] LPDWORD lpdwcRasAutodialAddresses
);
参数
[in, out] lppRasAutodialAddresses
指向字符串指针数组的指针,缓冲区末尾有额外的空间用于存储字符串本身。
输出时,每个字符串接收 AutoDial 映射数据库中的地址的名称。
如果 lppAddresses 在输入时为 NULL , 则 RasEnumAutodialAddresses 将设置 lpdwcbAddresses 和 lpdwcAddresses 参数,以指示数据库中所需的大小、字节数和地址条目数。
[in, out] lpdwcbRasAutodialAddresses
指向变量的指针,该变量在输入时包含 由 lpRasEnumAutodialAddressespAddresses 参数 指定的缓冲区的大小(以字节为单位)。
若要确定所需的缓冲区大小,请在 lppAddresses 设置为 NULL 的情况下调用 RasEnumAutodialAddresses。 lpdwcbAddresses 指向的变量应设置为零。 该函数将以 lpdwcbAddresses 形式返回所需的缓冲区大小和 错误代码ERROR_BUFFER_TOO_SMALL。
[out] lpdwcRasAutodialAddresses
指向一个变量的指针,该变量接收 lppAddresses 缓冲区中返回的地址字符串数。
返回值
如果函数成功,则返回值 ERROR_SUCCESS。
如果函数失败,则返回值为以下错误代码之一,或者来自 路由和远程访问错误代码 或 Winerror.h 的值。
值 | 含义 |
---|---|
|
已为 lpdwcbAddresses 或 lpdwcAddresses 参数传递 NULL。 |
|
lppAddresses 缓冲区为 NULL,lpdwcbAddresses 为零。 函数在 lpdwcbAddresses 指向的变量中返回所需的缓冲区大小。 |
注解
以下代码示例代码使用 RasEnumAutodialAddresses 枚举 Autodial 映射数据库。
#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "raserror.h"
#include <tchar.h>
DWORD __cdecl wmain(){
DWORD dwBytes = 0;
DWORD dwRet = ERROR_SUCCESS;
DWORD dwAddresses = 0;
LPTSTR * lppAddresses = NULL;
LPCTSTR lpEntryAddress = L"www.microsoft.com";
// Allocate memory for a new Autodial address to add to the mapping database
LPRASAUTODIALENTRY lpentry = (LPRASAUTODIALENTRY) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASAUTODIALENTRY));
lpentry->dwSize = sizeof(RASAUTODIALENTRY);
// Add a (non-functional) address to the Autodial mapping database
// (this ensures RasEnumAutodialAddresses() has something to return)
dwRet = RasSetAutodialAddress(lpEntryAddress, 0, lpentry, lpentry->dwSize, 1);
// Call RasEnumAutodialAddresses() with lppAddresses = NULL. dwBytes is returned with the
// required buffer size and a return code of ERROR_BUFFER_TOO_SMALL
dwRet = RasEnumAutodialAddresses(lppAddresses, &dwBytes, &dwAddresses);
if (dwRet == ERROR_BUFFER_TOO_SMALL){
// Allocate the memory needed for the array of RAS Autodial addresses.
lppAddresses = (LPTSTR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwBytes);
if (lppAddresses == NULL){
wprintf(L"HeapAlloc failed!\n");
return 0;
}
// Call RasEnumAutodialAddresses() to enumerate all RAS Autodial addresses
dwRet = RasEnumAutodialAddresses(lppAddresses, &dwBytes, &dwAddresses);
// If successful, print the RAS Autodial addresses
if (dwRet == ERROR_SUCCESS){
wprintf(L"The following RAS Autodial addresses were found:\n");
for (DWORD i = 0; i < dwAddresses; i++){
wprintf(L"%s\n", lppAddresses[i]);
}
}
// Remove the address
dwRet = RasSetAutodialAddress(lpEntryAddress, 0, NULL, 0, 0);
//Deallocate memory for the address buffers
HeapFree(GetProcessHeap(), 0, lppAddresses);
HeapFree(GetProcessHeap(), 0, lpentry);
lppAddresses = NULL;
return 0;
}
// There was either a problem with RAS or there are no RAS Autodial addresses to enumerate
if(dwAddresses >= 1){
wprintf(L"The operation failed to acquire the buffer size.\n");
}else{
wprintf(L"There were no RAS Autodial addresses found.\n");
}
// Remove the address
dwRet = RasSetAutodialAddress(lpEntryAddress, 0, NULL, 0, 0);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
注意
ras.h 标头将 RasEnumAutodialAddresses 定义为别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将非特定编码别名的使用与非非特定编码的代码混合使用可能会导致不匹配,从而导致编译或运行时错误。 有关详细信息,请参阅 函数原型的约定。
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 2000 Professional [仅限桌面应用] |
最低受支持的服务器 | Windows 2000 Server [仅限桌面应用] |
目标平台 | Windows |
标头 | ras.h |
Library | Rasapi32.lib |
DLL | Rasapi32.dll |