Win32 API 日本語リファレンス
ホームNetworkManagement.Rras › MprAdminEstablishDomainRasServer

MprAdminEstablishDomainRasServer

関数
ドメイン内のRASサーバー登録を有効または無効にする。
DLLMPRAPI.dll呼出規約winapi対応OSwindowsserver2003

シグネチャ

// MPRAPI.dll
#include <windows.h>

DWORD MprAdminEstablishDomainRasServer(
    LPWSTR pszDomain,
    LPWSTR pszMachine,
    BOOL bEnable
);

パラメーター

名前方向説明
pszDomainLPWSTRinRASサーバー登録を構成する対象ドメイン名の文字列。
pszMachineLPWSTRin登録対象のマシン名の文字列。
bEnableBOOLinTRUEで当該マシンをドメインのRASサーバーとして登録、FALSEで解除する真偽値。

戻り値の型: DWORD

各言語での呼び出し定義

// MPRAPI.dll
#include <windows.h>

DWORD MprAdminEstablishDomainRasServer(
    LPWSTR pszDomain,
    LPWSTR pszMachine,
    BOOL bEnable
);
[DllImport("MPRAPI.dll", ExactSpelling = true)]
static extern uint MprAdminEstablishDomainRasServer(
    [MarshalAs(UnmanagedType.LPWStr)] string pszDomain,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszMachine,   // LPWSTR
    bool bEnable   // BOOL
);
<DllImport("MPRAPI.dll", ExactSpelling:=True)>
Public Shared Function MprAdminEstablishDomainRasServer(
    <MarshalAs(UnmanagedType.LPWStr)> pszDomain As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszMachine As String,   ' LPWSTR
    bEnable As Boolean   ' BOOL
) As UInteger
End Function
' pszDomain : LPWSTR
' pszMachine : LPWSTR
' bEnable : BOOL
Declare PtrSafe Function MprAdminEstablishDomainRasServer Lib "mprapi" ( _
    ByVal pszDomain As LongPtr, _
    ByVal pszMachine As LongPtr, _
    ByVal bEnable As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MprAdminEstablishDomainRasServer = ctypes.windll.mprapi.MprAdminEstablishDomainRasServer
MprAdminEstablishDomainRasServer.restype = wintypes.DWORD
MprAdminEstablishDomainRasServer.argtypes = [
    wintypes.LPCWSTR,  # pszDomain : LPWSTR
    wintypes.LPCWSTR,  # pszMachine : LPWSTR
    wintypes.BOOL,  # bEnable : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPRAPI.dll')
MprAdminEstablishDomainRasServer = Fiddle::Function.new(
  lib['MprAdminEstablishDomainRasServer'],
  [
    Fiddle::TYPE_VOIDP,  # pszDomain : LPWSTR
    Fiddle::TYPE_VOIDP,  # pszMachine : LPWSTR
    Fiddle::TYPE_INT,  # bEnable : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "mprapi")]
extern "system" {
    fn MprAdminEstablishDomainRasServer(
        pszDomain: *mut u16,  // LPWSTR
        pszMachine: *mut u16,  // LPWSTR
        bEnable: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MPRAPI.dll")]
public static extern uint MprAdminEstablishDomainRasServer([MarshalAs(UnmanagedType.LPWStr)] string pszDomain, [MarshalAs(UnmanagedType.LPWStr)] string pszMachine, bool bEnable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPRAPI_MprAdminEstablishDomainRasServer' -Namespace Win32 -PassThru
# $api::MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
#uselib "MPRAPI.dll"
#func global MprAdminEstablishDomainRasServer "MprAdminEstablishDomainRasServer" sptr, sptr, sptr
; MprAdminEstablishDomainRasServer pszDomain, pszMachine, bEnable   ; 戻り値は stat
; pszDomain : LPWSTR -> "sptr"
; pszMachine : LPWSTR -> "sptr"
; bEnable : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MPRAPI.dll"
#cfunc global MprAdminEstablishDomainRasServer "MprAdminEstablishDomainRasServer" wstr, wstr, int
; res = MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
; pszDomain : LPWSTR -> "wstr"
; pszMachine : LPWSTR -> "wstr"
; bEnable : BOOL -> "int"
; DWORD MprAdminEstablishDomainRasServer(LPWSTR pszDomain, LPWSTR pszMachine, BOOL bEnable)
#uselib "MPRAPI.dll"
#cfunc global MprAdminEstablishDomainRasServer "MprAdminEstablishDomainRasServer" wstr, wstr, int
; res = MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
; pszDomain : LPWSTR -> "wstr"
; pszMachine : LPWSTR -> "wstr"
; bEnable : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mprapi = windows.NewLazySystemDLL("MPRAPI.dll")
	procMprAdminEstablishDomainRasServer = mprapi.NewProc("MprAdminEstablishDomainRasServer")
)

// pszDomain (LPWSTR), pszMachine (LPWSTR), bEnable (BOOL)
r1, _, err := procMprAdminEstablishDomainRasServer.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDomain))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszMachine))),
	uintptr(bEnable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MprAdminEstablishDomainRasServer(
  pszDomain: PWideChar;   // LPWSTR
  pszMachine: PWideChar;   // LPWSTR
  bEnable: BOOL   // BOOL
): DWORD; stdcall;
  external 'MPRAPI.dll' name 'MprAdminEstablishDomainRasServer';
result := DllCall("MPRAPI\MprAdminEstablishDomainRasServer"
    , "WStr", pszDomain   ; LPWSTR
    , "WStr", pszMachine   ; LPWSTR
    , "Int", bEnable   ; BOOL
    , "UInt")   ; return: DWORD
●MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable) = DLL("MPRAPI.dll", "dword MprAdminEstablishDomainRasServer(char*, char*, bool)")
# 呼び出し: MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
# pszDomain : LPWSTR -> "char*"
# pszMachine : LPWSTR -> "char*"
# bEnable : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mprapi" fn MprAdminEstablishDomainRasServer(
    pszDomain: [*c]const u16, // LPWSTR
    pszMachine: [*c]const u16, // LPWSTR
    bEnable: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
proc MprAdminEstablishDomainRasServer(
    pszDomain: WideCString,  # LPWSTR
    pszMachine: WideCString,  # LPWSTR
    bEnable: int32  # BOOL
): uint32 {.importc: "MprAdminEstablishDomainRasServer", stdcall, dynlib: "MPRAPI.dll".}
pragma(lib, "mprapi");
extern(Windows)
uint MprAdminEstablishDomainRasServer(
    const(wchar)* pszDomain,   // LPWSTR
    const(wchar)* pszMachine,   // LPWSTR
    int bEnable   // BOOL
);
ccall((:MprAdminEstablishDomainRasServer, "MPRAPI.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Int32),
      pszDomain, pszMachine, bEnable)
# pszDomain : LPWSTR -> Cwstring
# pszMachine : LPWSTR -> Cwstring
# bEnable : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MprAdminEstablishDomainRasServer(
    const uint16_t* pszDomain,
    const uint16_t* pszMachine,
    int32_t bEnable);
]]
local mprapi = ffi.load("mprapi")
-- mprapi.MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
-- pszDomain : LPWSTR
-- pszMachine : LPWSTR
-- bEnable : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MPRAPI.dll');
const MprAdminEstablishDomainRasServer = lib.func('__stdcall', 'MprAdminEstablishDomainRasServer', 'uint32_t', ['str16', 'str16', 'int32_t']);
// MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
// pszDomain : LPWSTR -> 'str16'
// pszMachine : LPWSTR -> 'str16'
// bEnable : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MPRAPI.dll", {
  MprAdminEstablishDomainRasServer: { parameters: ["buffer", "buffer", "i32"], result: "u32" },
});
// lib.symbols.MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable)
// pszDomain : LPWSTR -> "buffer"
// pszMachine : LPWSTR -> "buffer"
// bEnable : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MprAdminEstablishDomainRasServer(
    const uint16_t* pszDomain,
    const uint16_t* pszMachine,
    int32_t bEnable);
C, "MPRAPI.dll");
// $ffi->MprAdminEstablishDomainRasServer(pszDomain, pszMachine, bEnable);
// pszDomain : LPWSTR
// pszMachine : LPWSTR
// bEnable : BOOL
// 構造体/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 Mprapi extends StdCallLibrary {
    Mprapi INSTANCE = Native.load("mprapi", Mprapi.class);
    int MprAdminEstablishDomainRasServer(
        WString pszDomain,   // LPWSTR
        WString pszMachine,   // LPWSTR
        boolean bEnable   // BOOL
    );
}
@[Link("mprapi")]
lib LibMPRAPI
  fun MprAdminEstablishDomainRasServer = MprAdminEstablishDomainRasServer(
    pszDomain : UInt16*,   # LPWSTR
    pszMachine : UInt16*,   # LPWSTR
    bEnable : Int32   # BOOL
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MprAdminEstablishDomainRasServerNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef MprAdminEstablishDomainRasServerDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final MprAdminEstablishDomainRasServer = DynamicLibrary.open('MPRAPI.dll')
    .lookupFunction<MprAdminEstablishDomainRasServerNative, MprAdminEstablishDomainRasServerDart>('MprAdminEstablishDomainRasServer');
// pszDomain : LPWSTR -> Pointer<Utf16>
// pszMachine : LPWSTR -> Pointer<Utf16>
// bEnable : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MprAdminEstablishDomainRasServer(
  pszDomain: PWideChar;   // LPWSTR
  pszMachine: PWideChar;   // LPWSTR
  bEnable: BOOL   // BOOL
): DWORD; stdcall;
  external 'MPRAPI.dll' name 'MprAdminEstablishDomainRasServer';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MprAdminEstablishDomainRasServer"
  c_MprAdminEstablishDomainRasServer :: CWString -> CWString -> CInt -> IO Word32
-- pszDomain : LPWSTR -> CWString
-- pszMachine : LPWSTR -> CWString
-- bEnable : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mpradminestablishdomainrasserver =
  foreign "MprAdminEstablishDomainRasServer"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* pszDomain : LPWSTR -> (ptr uint16_t) *)
(* pszMachine : LPWSTR -> (ptr uint16_t) *)
(* bEnable : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mprapi (t "MPRAPI.dll"))
(cffi:use-foreign-library mprapi)

(cffi:defcfun ("MprAdminEstablishDomainRasServer" mpr-admin-establish-domain-ras-server :convention :stdcall) :uint32
  (psz-domain (:string :encoding :utf-16le))   ; LPWSTR
  (psz-machine (:string :encoding :utf-16le))   ; LPWSTR
  (b-enable :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MprAdminEstablishDomainRasServer = Win32::API::More->new('MPRAPI',
    'DWORD MprAdminEstablishDomainRasServer(LPCWSTR pszDomain, LPCWSTR pszMachine, BOOL bEnable)');
# my $ret = $MprAdminEstablishDomainRasServer->Call($pszDomain, $pszMachine, $bEnable);
# pszDomain : LPWSTR -> LPCWSTR
# pszMachine : LPWSTR -> LPCWSTR
# bEnable : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。