RasDeleteEntryA 函数 (ras.h)
RasDeleteEntry 函数从电话簿中删除条目。
语法
DWORD RasDeleteEntryA(
[in] LPCSTR unnamedParam1,
[in] LPCSTR unnamedParam2
);
参数
[in] unnamedParam1
指向以 null 结尾的字符串的指针,该字符串指定电话簿 (PBK) 文件的完整路径和文件名。 如果此参数 NULL,则该函数使用当前的默认电话簿文件。 默认电话簿文件是用户在 用户首选项拨号网络 对话框中选择的文件。
Windows Me/98/95:此参数应始终 NULL。 拨号网络将电话簿条目存储在注册表中,而不是存储在电话簿文件中。
[in] unnamedParam2
指向以 null 结尾的字符串的指针,该字符串指定要删除的现有条目的名称。
返回值
如果函数成功,则返回值 ERROR_SUCCESS。
如果函数失败,则返回值是以下错误代码之一或来自 路由和远程访问错误代码 或 Winerror.h 的值。
价值 | 意义 |
---|---|
|
用户没有正确的权限。 只有管理员才能完成此任务。 |
|
lpszEntry 中指定的条目名称不存在。 |
言论
以下示例代码删除变量 lpszEntry指定的电话簿条目。
#include <stdio.h>
#include <windows.h>
#include "ras.h"
#include "strsafe.h"
#define PHONE_NUMBER_LENGTH 7
#define DEVICE_NAME_LENGTH 5
#define DEVICE_TYPE_LENGTH 5
DWORD __cdecl wmain(){
DWORD dwRet = ERROR_SUCCESS;
LPTSTR lpszEntry = L"RASEntryName";
LPTSTR lpszphonenumber = L"5555555";
LPTSTR lpszdevicename = L"Modem";
LPTSTR lpszdevicetype = RASDT_Modem;
// Allocate heap memory for the RASENTRY structure
LPRASENTRY lpentry = (LPRASENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASENTRY));
if (lpentry == NULL){
printf("HeapAlloc failed");
return 0;
}
// The RASENTRY->dwSize member has to be initialized or the RRAS APIs will fail below.
lpentry->dwSize = sizeof(RASENTRY);
lpentry->dwFramingProtocol = RASFP_Ppp;
lpentry->dwfOptions = 0;
lpentry->dwType = RASET_Phone;
dwRet |= StringCchCopyN(lpentry->szLocalPhoneNumber, RAS_MaxPhoneNumber, lpszphonenumber, PHONE_NUMBER_LENGTH);
dwRet |= StringCchCopyN(lpentry->szDeviceName, RAS_MaxDeviceName, lpszdevicename, DEVICE_NAME_LENGTH);
dwRet |= StringCchCopyN(lpentry->szDeviceType, RAS_MaxDeviceType, lpszdevicetype, DEVICE_TYPE_LENGTH);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RASENTRY structure initialization failed");
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// Validate the new entry's name
dwRet = RasValidateEntryName(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasValidateEntryName failed: Error = %d\n", dwRet);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// Create and set the new entry's properties
dwRet = RasSetEntryProperties(NULL, lpszEntry, lpentry, lpentry->dwSize, NULL, 0);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasSetEntryProperties failed: Error = %d\n", dwRet);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// Clean up: delete the new entry
dwRet = RasDeleteEntry(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasDeleteEntry failed: Error = %d\n", dwRet);
}
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
注意
ras.h 标头将 RasDeleteEntry 定义为一个别名,该别名根据 UNICODE 预处理器常量的定义自动选择此函数的 ANSI 或 Unicode 版本。 将中性编码别名与不中性编码的代码混合使用可能会导致编译或运行时错误不匹配。 有关详细信息,请参阅函数原型的
要求
要求 | 价值 |
---|---|
最低支持的客户端 | Windows 2000 Professional [仅限桌面应用] |
支持的最低服务器 | Windows 2000 Server [仅限桌面应用] |
目标平台 | 窗户 |
标头 | ras.h |
库 | Rasapi32.lib |
DLL | Rasapi32.dll |