ホーム › NetworkManagement.Rras › RasDeleteEntryW
RasDeleteEntryW
関数RAS電話帳エントリを削除する(Unicode版)。
シグネチャ
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasDeleteEntryW(
LPCWSTR param0, // optional
LPCWSTR param1
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| param0 | LPCWSTR | inoptional | 電話帳ファイルのフルパス文字列。NULL指定で既定の電話帳を使用する。 |
| param1 | LPCWSTR | in | 削除する対象エントリ名の文字列。 |
戻り値の型: DWORD
公式ドキュメント
RasDeleteEntry 関数は、電話帳からエントリを削除します。(Unicode)
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は次のいずれかのエラー コード、または Routing and Remote Access Error Codes もしくは Winerror.h の値です。
| 値 | 意味 |
|---|---|
| ユーザーが適切な特権を持っていません。このタスクを実行できるのは管理者だけです。 | |
| lpszEntry で指定されたエントリ名が存在しません。 |
解説(Remarks)
次のサンプル コードは、変数 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;
// RASENTRY 構造体用にヒープ メモリを割り当てる
LPRASENTRY lpentry = (LPRASENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASENTRY));
if (lpentry == NULL){
printf("HeapAlloc failed");
return 0;
}
// RASENTRY->dwSize メンバーを初期化しないと、以降の RRAS API は失敗します。
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;
}
// 新しいエントリの名前を検証する
dwRet = RasValidateEntryName(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasValidateEntryName failed: Error = %d\n", dwRet);
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
// 新しいエントリを作成し、そのプロパティを設定する
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;
}
// クリーンアップ: 新しいエントリを削除する
dwRet = RasDeleteEntry(NULL, lpszEntry);
if (dwRet != ERROR_SUCCESS){
wprintf(L"RasDeleteEntry failed: Error = %d\n", dwRet);
}
HeapFree(GetProcessHeap(), 0, lpentry);
return 0;
}
メモ
ras.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして RasDeleteEntry を定義しています。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイル エラーや実行時エラーの原因になることがあります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasDeleteEntryW(
LPCWSTR param0, // optional
LPCWSTR param1
);[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RasDeleteEntryW(
[MarshalAs(UnmanagedType.LPWStr)] string param0, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string param1 // LPCWSTR
);<DllImport("RASAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RasDeleteEntryW(
<MarshalAs(UnmanagedType.LPWStr)> param0 As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> param1 As String ' LPCWSTR
) As UInteger
End Function' param0 : LPCWSTR optional
' param1 : LPCWSTR
Declare PtrSafe Function RasDeleteEntryW Lib "rasapi32" ( _
ByVal param0 As LongPtr, _
ByVal param1 As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RasDeleteEntryW = ctypes.windll.rasapi32.RasDeleteEntryW
RasDeleteEntryW.restype = wintypes.DWORD
RasDeleteEntryW.argtypes = [
wintypes.LPCWSTR, # param0 : LPCWSTR optional
wintypes.LPCWSTR, # param1 : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RASAPI32.dll')
RasDeleteEntryW = Fiddle::Function.new(
lib['RasDeleteEntryW'],
[
Fiddle::TYPE_VOIDP, # param0 : LPCWSTR optional
Fiddle::TYPE_VOIDP, # param1 : LPCWSTR
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rasapi32")]
extern "system" {
fn RasDeleteEntryW(
param0: *const u16, // LPCWSTR optional
param1: *const u16 // LPCWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RasDeleteEntryW([MarshalAs(UnmanagedType.LPWStr)] string param0, [MarshalAs(UnmanagedType.LPWStr)] string param1);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RASAPI32_RasDeleteEntryW' -Namespace Win32 -PassThru
# $api::RasDeleteEntryW(param0, param1)#uselib "RASAPI32.dll"
#func global RasDeleteEntryW "RasDeleteEntryW" wptr, wptr
; RasDeleteEntryW param0, param1 ; 戻り値は stat
; param0 : LPCWSTR optional -> "wptr"
; param1 : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "RASAPI32.dll"
#cfunc global RasDeleteEntryW "RasDeleteEntryW" wstr, wstr
; res = RasDeleteEntryW(param0, param1)
; param0 : LPCWSTR optional -> "wstr"
; param1 : LPCWSTR -> "wstr"; DWORD RasDeleteEntryW(LPCWSTR param0, LPCWSTR param1)
#uselib "RASAPI32.dll"
#cfunc global RasDeleteEntryW "RasDeleteEntryW" wstr, wstr
; res = RasDeleteEntryW(param0, param1)
; param0 : LPCWSTR optional -> "wstr"
; param1 : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rasapi32 = windows.NewLazySystemDLL("RASAPI32.dll")
procRasDeleteEntryW = rasapi32.NewProc("RasDeleteEntryW")
)
// param0 (LPCWSTR optional), param1 (LPCWSTR)
r1, _, err := procRasDeleteEntryW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param0))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param1))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RasDeleteEntryW(
param0: PWideChar; // LPCWSTR optional
param1: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasDeleteEntryW';result := DllCall("RASAPI32\RasDeleteEntryW"
, "WStr", param0 ; LPCWSTR optional
, "WStr", param1 ; LPCWSTR
, "UInt") ; return: DWORD●RasDeleteEntryW(param0, param1) = DLL("RASAPI32.dll", "dword RasDeleteEntryW(char*, char*)")
# 呼び出し: RasDeleteEntryW(param0, param1)
# param0 : LPCWSTR optional -> "char*"
# param1 : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rasapi32" fn RasDeleteEntryW(
param0: [*c]const u16, // LPCWSTR optional
param1: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RasDeleteEntryW(
param0: WideCString, # LPCWSTR optional
param1: WideCString # LPCWSTR
): uint32 {.importc: "RasDeleteEntryW", stdcall, dynlib: "RASAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rasapi32");
extern(Windows)
uint RasDeleteEntryW(
const(wchar)* param0, // LPCWSTR optional
const(wchar)* param1 // LPCWSTR
);ccall((:RasDeleteEntryW, "RASAPI32.dll"), stdcall, UInt32,
(Cwstring, Cwstring),
param0, param1)
# param0 : LPCWSTR optional -> Cwstring
# param1 : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RasDeleteEntryW(
const uint16_t* param0,
const uint16_t* param1);
]]
local rasapi32 = ffi.load("rasapi32")
-- rasapi32.RasDeleteEntryW(param0, param1)
-- param0 : LPCWSTR optional
-- param1 : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('RASAPI32.dll');
const RasDeleteEntryW = lib.func('__stdcall', 'RasDeleteEntryW', 'uint32_t', ['str16', 'str16']);
// RasDeleteEntryW(param0, param1)
// param0 : LPCWSTR optional -> 'str16'
// param1 : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RASAPI32.dll", {
RasDeleteEntryW: { parameters: ["buffer", "buffer"], result: "u32" },
});
// lib.symbols.RasDeleteEntryW(param0, param1)
// param0 : LPCWSTR optional -> "buffer"
// param1 : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RasDeleteEntryW(
const uint16_t* param0,
const uint16_t* param1);
C, "RASAPI32.dll");
// $ffi->RasDeleteEntryW(param0, param1);
// param0 : LPCWSTR optional
// param1 : LPCWSTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Rasapi32 extends StdCallLibrary {
Rasapi32 INSTANCE = Native.load("rasapi32", Rasapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RasDeleteEntryW(
WString param0, // LPCWSTR optional
WString param1 // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rasapi32")]
lib LibRASAPI32
fun RasDeleteEntryW = RasDeleteEntryW(
param0 : UInt16*, # LPCWSTR optional
param1 : UInt16* # LPCWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RasDeleteEntryWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef RasDeleteEntryWDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final RasDeleteEntryW = DynamicLibrary.open('RASAPI32.dll')
.lookupFunction<RasDeleteEntryWNative, RasDeleteEntryWDart>('RasDeleteEntryW');
// param0 : LPCWSTR optional -> Pointer<Utf16>
// param1 : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RasDeleteEntryW(
param0: PWideChar; // LPCWSTR optional
param1: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasDeleteEntryW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RasDeleteEntryW"
c_RasDeleteEntryW :: CWString -> CWString -> IO Word32
-- param0 : LPCWSTR optional -> CWString
-- param1 : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rasdeleteentryw =
foreign "RasDeleteEntryW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* param0 : LPCWSTR optional -> (ptr uint16_t) *)
(* param1 : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rasapi32 (t "RASAPI32.dll"))
(cffi:use-foreign-library rasapi32)
(cffi:defcfun ("RasDeleteEntryW" ras-delete-entry-w :convention :stdcall) :uint32
(param0 (:string :encoding :utf-16le)) ; LPCWSTR optional
(param1 (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RasDeleteEntryW = Win32::API::More->new('RASAPI32',
'DWORD RasDeleteEntryW(LPCWSTR param0, LPCWSTR param1)');
# my $ret = $RasDeleteEntryW->Call($param0, $param1);
# param0 : LPCWSTR optional -> LPCWSTR
# param1 : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RasDeleteEntryA (ANSI版) — RAS電話帳エントリを削除する(ANSI版)。
公式の関連項目
- f RasCreatePhonebookEntryW — ダイアログを表示し新しい電話帳エントリを作成する(Unicode版)。
- f RasEnumEntriesW — 電話帳内のRAS接続エントリ名を列挙する(Unicode版)。