Win32 API 日本語リファレンス
ホームSystem.Rpc › RpcNsBindingExportPnPW

RpcNsBindingExportPnPW

関数
プラグアンドプレイ対応でネームサービスにバインディングをエクスポートする(Unicode版)。
DLLRPCNS4.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// RPCNS4.dll  (Unicode / -W)
#include <windows.h>

RPC_STATUS RpcNsBindingExportPnPW(
    DWORD EntryNameSyntax,
    LPWSTR EntryName,   // optional
    void* IfSpec,   // optional
    UUID_VECTOR* ObjectVector   // optional
);

パラメーター

名前方向説明
EntryNameSyntaxDWORDin

EntryName の構文。

レジストリ値エントリ HKEY_LOCAL_MACHINE\Software\Microsoft\Rpc\NameService\DefaultSyntax で指定された構文を使用するには、RPC_C_NS_SYNTAX_DEFAULT を指定します。

EntryNameLPWSTRinoptional

バインディング ハンドルとオブジェクト UUID のエクスポート先となるエントリ名へのポインター。null または空の文字列を指定することはできません。

レジストリ値エントリ HKEY_LOCAL_MACHINE\Software\Microsoft\Rpc\NameService\DefaultEntry で指定されたエントリ名を使用するには、null ポインターまたは空の文字列を指定します。この場合、EntryNameSyntax パラメーターは無視され、ランタイム ライブラリは既定の構文を使用します。

IfSpecvoid*inoptionalエクスポートするインターフェイスを指定する、スタブが生成したデータ構造体。null 値は、エクスポートするバインディング ハンドルがない (オブジェクト UUID のみをエクスポートする) ことを示し、BindingVec は無視されます。
ObjectVectorUUID_VECTOR*inoptionalサーバーが提供するオブジェクト UUID のベクターへのポインター。サーバー アプリケーションがこのベクターを構築します。null 値は、エクスポートするオブジェクト UUID がない (バインディング ハンドルのみをエクスポートする) ことを示します。

戻り値の型: RPC_STATUS

公式ドキュメント

RpcNsBindingExportPnP 関数は、プラグ アンド プレイをサポートするサーバーのために、複数のバインディング ハンドルと複数のオブジェクトを持つネーム サービス データベース エントリを確立します。(Unicode)

戻り値

意味
RPC_S_OK
呼び出しに成功しました。
RPC_S_NOTHING_TO_EXPORT
エクスポートするものがありませんでした。
RPC_S_INVALID_BINDING
バインディング ハンドルが無効でした。
RPC_S_WRONG_KIND_OF_BINDING
この操作に対して誤った種類のバインディングでした。
RPC_S_INVALID_NAME_SYNTAX
名前の構文が無効です。
RPC_S_UNSUPPORTED_NAME_SYNTAX
名前の構文がサポートされていません。
RPC_S_INCOMPLETE_NAME
名前が不完全です。
RPC_S_NO_NS_PRIVILEGE
ネーム サービス操作を行う特権がありません。
RPC_S_NAME_SERVICE_UNAVAILABLE
ネーム サービスを利用できません。
メモ 有効なエラー コードの一覧については、 RPC の戻り値を参照してください。

解説(Remarks)

RpcNsBindingExportPnP 関数を使用すると、サーバー アプリケーションは、任意のクライアント アプリケーションが使用できるように、プラグ アンド プレイ バインディングをサポートするインターフェイスをネーム サービス データベース上で公開できます。

プラグ アンド プレイ バインディングをエクスポートする場合、サーバー アプリケーションはバインディング ベクターを明示的に指定すべきではないことに注意してください。プラグ アンド プレイ イベントによってバインディングが変化した際には、バインディングは自動的に更新されます。

メモ

rpcnsi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして RpcNsBindingExportPnP を定義しています。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在させて使用すると、不一致が生じてコンパイル エラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則 を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// RPCNS4.dll  (Unicode / -W)
#include <windows.h>

RPC_STATUS RpcNsBindingExportPnPW(
    DWORD EntryNameSyntax,
    LPWSTR EntryName,   // optional
    void* IfSpec,   // optional
    UUID_VECTOR* ObjectVector   // optional
);
[DllImport("RPCNS4.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int RpcNsBindingExportPnPW(
    uint EntryNameSyntax,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string EntryName,   // LPWSTR optional
    IntPtr IfSpec,   // void* optional
    IntPtr ObjectVector   // UUID_VECTOR* optional
);
<DllImport("RPCNS4.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RpcNsBindingExportPnPW(
    EntryNameSyntax As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> EntryName As String,   ' LPWSTR optional
    IfSpec As IntPtr,   ' void* optional
    ObjectVector As IntPtr   ' UUID_VECTOR* optional
) As Integer
End Function
' EntryNameSyntax : DWORD
' EntryName : LPWSTR optional
' IfSpec : void* optional
' ObjectVector : UUID_VECTOR* optional
Declare PtrSafe Function RpcNsBindingExportPnPW Lib "rpcns4" ( _
    ByVal EntryNameSyntax As Long, _
    ByVal EntryName As LongPtr, _
    ByVal IfSpec As LongPtr, _
    ByVal ObjectVector 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

RpcNsBindingExportPnPW = ctypes.windll.rpcns4.RpcNsBindingExportPnPW
RpcNsBindingExportPnPW.restype = ctypes.c_int
RpcNsBindingExportPnPW.argtypes = [
    wintypes.DWORD,  # EntryNameSyntax : DWORD
    wintypes.LPCWSTR,  # EntryName : LPWSTR optional
    ctypes.POINTER(None),  # IfSpec : void* optional
    ctypes.c_void_p,  # ObjectVector : UUID_VECTOR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('RPCNS4.dll')
RpcNsBindingExportPnPW = Fiddle::Function.new(
  lib['RpcNsBindingExportPnPW'],
  [
    -Fiddle::TYPE_INT,  # EntryNameSyntax : DWORD
    Fiddle::TYPE_VOIDP,  # EntryName : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # IfSpec : void* optional
    Fiddle::TYPE_VOIDP,  # ObjectVector : UUID_VECTOR* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "rpcns4")]
extern "system" {
    fn RpcNsBindingExportPnPW(
        EntryNameSyntax: u32,  // DWORD
        EntryName: *mut u16,  // LPWSTR optional
        IfSpec: *mut (),  // void* optional
        ObjectVector: *mut UUID_VECTOR  // UUID_VECTOR* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("RPCNS4.dll", CharSet = CharSet.Unicode)]
public static extern int RpcNsBindingExportPnPW(uint EntryNameSyntax, [MarshalAs(UnmanagedType.LPWStr)] string EntryName, IntPtr IfSpec, IntPtr ObjectVector);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RPCNS4_RpcNsBindingExportPnPW' -Namespace Win32 -PassThru
# $api::RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
#uselib "RPCNS4.dll"
#func global RpcNsBindingExportPnPW "RpcNsBindingExportPnPW" wptr, wptr, wptr, wptr
; RpcNsBindingExportPnPW EntryNameSyntax, EntryName, IfSpec, varptr(ObjectVector)   ; 戻り値は stat
; EntryNameSyntax : DWORD -> "wptr"
; EntryName : LPWSTR optional -> "wptr"
; IfSpec : void* optional -> "wptr"
; ObjectVector : UUID_VECTOR* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "RPCNS4.dll"
#cfunc global RpcNsBindingExportPnPW "RpcNsBindingExportPnPW" int, wstr, sptr, var
; res = RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
; EntryNameSyntax : DWORD -> "int"
; EntryName : LPWSTR optional -> "wstr"
; IfSpec : void* optional -> "sptr"
; ObjectVector : UUID_VECTOR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; RPC_STATUS RpcNsBindingExportPnPW(DWORD EntryNameSyntax, LPWSTR EntryName, void* IfSpec, UUID_VECTOR* ObjectVector)
#uselib "RPCNS4.dll"
#cfunc global RpcNsBindingExportPnPW "RpcNsBindingExportPnPW" int, wstr, intptr, var
; res = RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
; EntryNameSyntax : DWORD -> "int"
; EntryName : LPWSTR optional -> "wstr"
; IfSpec : void* optional -> "intptr"
; ObjectVector : UUID_VECTOR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	rpcns4 = windows.NewLazySystemDLL("RPCNS4.dll")
	procRpcNsBindingExportPnPW = rpcns4.NewProc("RpcNsBindingExportPnPW")
)

// EntryNameSyntax (DWORD), EntryName (LPWSTR optional), IfSpec (void* optional), ObjectVector (UUID_VECTOR* optional)
r1, _, err := procRpcNsBindingExportPnPW.Call(
	uintptr(EntryNameSyntax),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(EntryName))),
	uintptr(IfSpec),
	uintptr(ObjectVector),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // RPC_STATUS
function RpcNsBindingExportPnPW(
  EntryNameSyntax: DWORD;   // DWORD
  EntryName: PWideChar;   // LPWSTR optional
  IfSpec: Pointer;   // void* optional
  ObjectVector: Pointer   // UUID_VECTOR* optional
): Integer; stdcall;
  external 'RPCNS4.dll' name 'RpcNsBindingExportPnPW';
result := DllCall("RPCNS4\RpcNsBindingExportPnPW"
    , "UInt", EntryNameSyntax   ; DWORD
    , "WStr", EntryName   ; LPWSTR optional
    , "Ptr", IfSpec   ; void* optional
    , "Ptr", ObjectVector   ; UUID_VECTOR* optional
    , "Int")   ; return: RPC_STATUS
●RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector) = DLL("RPCNS4.dll", "int RpcNsBindingExportPnPW(dword, char*, void*, void*)")
# 呼び出し: RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
# EntryNameSyntax : DWORD -> "dword"
# EntryName : LPWSTR optional -> "char*"
# IfSpec : void* optional -> "void*"
# ObjectVector : UUID_VECTOR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "rpcns4" fn RpcNsBindingExportPnPW(
    EntryNameSyntax: u32, // DWORD
    EntryName: [*c]const u16, // LPWSTR optional
    IfSpec: ?*anyopaque, // void* optional
    ObjectVector: [*c]UUID_VECTOR // UUID_VECTOR* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc RpcNsBindingExportPnPW(
    EntryNameSyntax: uint32,  # DWORD
    EntryName: WideCString,  # LPWSTR optional
    IfSpec: pointer,  # void* optional
    ObjectVector: ptr UUID_VECTOR  # UUID_VECTOR* optional
): int32 {.importc: "RpcNsBindingExportPnPW", stdcall, dynlib: "RPCNS4.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "rpcns4");
extern(Windows)
int RpcNsBindingExportPnPW(
    uint EntryNameSyntax,   // DWORD
    const(wchar)* EntryName,   // LPWSTR optional
    void* IfSpec,   // void* optional
    UUID_VECTOR* ObjectVector   // UUID_VECTOR* optional
);
ccall((:RpcNsBindingExportPnPW, "RPCNS4.dll"), stdcall, Int32,
      (UInt32, Cwstring, Ptr{Cvoid}, Ptr{UUID_VECTOR}),
      EntryNameSyntax, EntryName, IfSpec, ObjectVector)
# EntryNameSyntax : DWORD -> UInt32
# EntryName : LPWSTR optional -> Cwstring
# IfSpec : void* optional -> Ptr{Cvoid}
# ObjectVector : UUID_VECTOR* optional -> Ptr{UUID_VECTOR}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t RpcNsBindingExportPnPW(
    uint32_t EntryNameSyntax,
    const uint16_t* EntryName,
    void* IfSpec,
    void* ObjectVector);
]]
local rpcns4 = ffi.load("rpcns4")
-- rpcns4.RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
-- EntryNameSyntax : DWORD
-- EntryName : LPWSTR optional
-- IfSpec : void* optional
-- ObjectVector : UUID_VECTOR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('RPCNS4.dll');
const RpcNsBindingExportPnPW = lib.func('__stdcall', 'RpcNsBindingExportPnPW', 'int32_t', ['uint32_t', 'str16', 'void *', 'void *']);
// RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
// EntryNameSyntax : DWORD -> 'uint32_t'
// EntryName : LPWSTR optional -> 'str16'
// IfSpec : void* optional -> 'void *'
// ObjectVector : UUID_VECTOR* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("RPCNS4.dll", {
  RpcNsBindingExportPnPW: { parameters: ["u32", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector)
// EntryNameSyntax : DWORD -> "u32"
// EntryName : LPWSTR optional -> "buffer"
// IfSpec : void* optional -> "pointer"
// ObjectVector : UUID_VECTOR* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RpcNsBindingExportPnPW(
    uint32_t EntryNameSyntax,
    const uint16_t* EntryName,
    void* IfSpec,
    void* ObjectVector);
C, "RPCNS4.dll");
// $ffi->RpcNsBindingExportPnPW(EntryNameSyntax, EntryName, IfSpec, ObjectVector);
// EntryNameSyntax : DWORD
// EntryName : LPWSTR optional
// IfSpec : void* optional
// ObjectVector : UUID_VECTOR* optional
// 構造体/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 Rpcns4 extends StdCallLibrary {
    Rpcns4 INSTANCE = Native.load("rpcns4", Rpcns4.class, W32APIOptions.UNICODE_OPTIONS);
    int RpcNsBindingExportPnPW(
        int EntryNameSyntax,   // DWORD
        WString EntryName,   // LPWSTR optional
        Pointer IfSpec,   // void* optional
        Pointer ObjectVector   // UUID_VECTOR* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("rpcns4")]
lib LibRPCNS4
  fun RpcNsBindingExportPnPW = RpcNsBindingExportPnPW(
    EntryNameSyntax : UInt32,   # DWORD
    EntryName : UInt16*,   # LPWSTR optional
    IfSpec : Void*,   # void* optional
    ObjectVector : UUID_VECTOR*   # UUID_VECTOR* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RpcNsBindingExportPnPWNative = Int32 Function(Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef RpcNsBindingExportPnPWDart = int Function(int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final RpcNsBindingExportPnPW = DynamicLibrary.open('RPCNS4.dll')
    .lookupFunction<RpcNsBindingExportPnPWNative, RpcNsBindingExportPnPWDart>('RpcNsBindingExportPnPW');
// EntryNameSyntax : DWORD -> Uint32
// EntryName : LPWSTR optional -> Pointer<Utf16>
// IfSpec : void* optional -> Pointer<Void>
// ObjectVector : UUID_VECTOR* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RpcNsBindingExportPnPW(
  EntryNameSyntax: DWORD;   // DWORD
  EntryName: PWideChar;   // LPWSTR optional
  IfSpec: Pointer;   // void* optional
  ObjectVector: Pointer   // UUID_VECTOR* optional
): Integer; stdcall;
  external 'RPCNS4.dll' name 'RpcNsBindingExportPnPW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RpcNsBindingExportPnPW"
  c_RpcNsBindingExportPnPW :: Word32 -> CWString -> Ptr () -> Ptr () -> IO Int32
-- EntryNameSyntax : DWORD -> Word32
-- EntryName : LPWSTR optional -> CWString
-- IfSpec : void* optional -> Ptr ()
-- ObjectVector : UUID_VECTOR* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rpcnsbindingexportpnpw =
  foreign "RpcNsBindingExportPnPW"
    (uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* EntryNameSyntax : DWORD -> uint32_t *)
(* EntryName : LPWSTR optional -> (ptr uint16_t) *)
(* IfSpec : void* optional -> (ptr void) *)
(* ObjectVector : UUID_VECTOR* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rpcns4 (t "RPCNS4.dll"))
(cffi:use-foreign-library rpcns4)

(cffi:defcfun ("RpcNsBindingExportPnPW" rpc-ns-binding-export-pn-pw :convention :stdcall) :int32
  (entry-name-syntax :uint32)   ; DWORD
  (entry-name (:string :encoding :utf-16le))   ; LPWSTR optional
  (if-spec :pointer)   ; void* optional
  (object-vector :pointer))   ; UUID_VECTOR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RpcNsBindingExportPnPW = Win32::API::More->new('RPCNS4',
    'int RpcNsBindingExportPnPW(DWORD EntryNameSyntax, LPCWSTR EntryName, LPVOID IfSpec, LPVOID ObjectVector)');
# my $ret = $RpcNsBindingExportPnPW->Call($EntryNameSyntax, $EntryName, $IfSpec, $ObjectVector);
# EntryNameSyntax : DWORD -> DWORD
# EntryName : LPWSTR optional -> LPCWSTR
# IfSpec : void* optional -> LPVOID
# ObjectVector : UUID_VECTOR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目
使用する型