Win32 API 日本語リファレンス
ホームNetworking.ActiveDirectory › DsRoleGetPrimaryDomainInformation

DsRoleGetPrimaryDomainInformation

関数
コンピューターのプライマリドメインとロール情報を取得する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsRoleGetPrimaryDomainInformation(
    LPCWSTR lpServer,
    DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
    BYTE** Buffer
);

パラメーター

名前方向説明
lpServerLPCWSTRin情報を取得する対象コンピュータ名を指すワイド文字列。ローカルマシンの場合はNULL可。
InfoLevelDSROLE_PRIMARY_DOMAIN_INFO_LEVELin取得するドメインロール情報のレベルを示す列挙値。返却構造体の種類を決める。
BufferBYTE**inout割り当てられた情報構造体へのポインタを受け取る出力。使用後はDsRoleFreeMemoryで解放する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsRoleGetPrimaryDomainInformation(
    LPCWSTR lpServer,
    DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
    BYTE** Buffer
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint DsRoleGetPrimaryDomainInformation(
    [MarshalAs(UnmanagedType.LPWStr)] string lpServer,   // LPCWSTR
    int InfoLevel,   // DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
    IntPtr Buffer   // BYTE** in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function DsRoleGetPrimaryDomainInformation(
    <MarshalAs(UnmanagedType.LPWStr)> lpServer As String,   ' LPCWSTR
    InfoLevel As Integer,   ' DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
    Buffer As IntPtr   ' BYTE** in/out
) As UInteger
End Function
' lpServer : LPCWSTR
' InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
' Buffer : BYTE** in/out
Declare PtrSafe Function DsRoleGetPrimaryDomainInformation Lib "netapi32" ( _
    ByVal lpServer As LongPtr, _
    ByVal InfoLevel As Long, _
    ByVal Buffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DsRoleGetPrimaryDomainInformation = ctypes.windll.netapi32.DsRoleGetPrimaryDomainInformation
DsRoleGetPrimaryDomainInformation.restype = wintypes.DWORD
DsRoleGetPrimaryDomainInformation.argtypes = [
    wintypes.LPCWSTR,  # lpServer : LPCWSTR
    ctypes.c_int,  # InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
    ctypes.c_void_p,  # Buffer : BYTE** in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
DsRoleGetPrimaryDomainInformation = Fiddle::Function.new(
  lib['DsRoleGetPrimaryDomainInformation'],
  [
    Fiddle::TYPE_VOIDP,  # lpServer : LPCWSTR
    Fiddle::TYPE_INT,  # InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
    Fiddle::TYPE_VOIDP,  # Buffer : BYTE** in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn DsRoleGetPrimaryDomainInformation(
        lpServer: *const u16,  // LPCWSTR
        InfoLevel: i32,  // DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
        Buffer: *mut *mut u8  // BYTE** in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint DsRoleGetPrimaryDomainInformation([MarshalAs(UnmanagedType.LPWStr)] string lpServer, int InfoLevel, IntPtr Buffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_DsRoleGetPrimaryDomainInformation' -Namespace Win32 -PassThru
# $api::DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, Buffer)
#uselib "NETAPI32.dll"
#func global DsRoleGetPrimaryDomainInformation "DsRoleGetPrimaryDomainInformation" sptr, sptr, sptr
; DsRoleGetPrimaryDomainInformation lpServer, InfoLevel, varptr(Buffer)   ; 戻り値は stat
; lpServer : LPCWSTR -> "sptr"
; InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> "sptr"
; Buffer : BYTE** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global DsRoleGetPrimaryDomainInformation "DsRoleGetPrimaryDomainInformation" wstr, int, var
; res = DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, Buffer)
; lpServer : LPCWSTR -> "wstr"
; InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> "int"
; Buffer : BYTE** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DsRoleGetPrimaryDomainInformation(LPCWSTR lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, BYTE** Buffer)
#uselib "NETAPI32.dll"
#cfunc global DsRoleGetPrimaryDomainInformation "DsRoleGetPrimaryDomainInformation" wstr, int, var
; res = DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, Buffer)
; lpServer : LPCWSTR -> "wstr"
; InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> "int"
; Buffer : BYTE** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procDsRoleGetPrimaryDomainInformation = netapi32.NewProc("DsRoleGetPrimaryDomainInformation")
)

// lpServer (LPCWSTR), InfoLevel (DSROLE_PRIMARY_DOMAIN_INFO_LEVEL), Buffer (BYTE** in/out)
r1, _, err := procDsRoleGetPrimaryDomainInformation.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpServer))),
	uintptr(InfoLevel),
	uintptr(Buffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsRoleGetPrimaryDomainInformation(
  lpServer: PWideChar;   // LPCWSTR
  InfoLevel: Integer;   // DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
  Buffer: Pointer   // BYTE** in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DsRoleGetPrimaryDomainInformation';
result := DllCall("NETAPI32\DsRoleGetPrimaryDomainInformation"
    , "WStr", lpServer   ; LPCWSTR
    , "Int", InfoLevel   ; DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
    , "Ptr", Buffer   ; BYTE** in/out
    , "UInt")   ; return: DWORD
●DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, Buffer) = DLL("NETAPI32.dll", "dword DsRoleGetPrimaryDomainInformation(char*, int, void*)")
# 呼び出し: DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, Buffer)
# lpServer : LPCWSTR -> "char*"
# InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> "int"
# Buffer : BYTE** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DsRoleGetPrimaryDomainInformationNative = Uint32 Function(Pointer<Utf16>, Int32, Pointer<Uint8>);
typedef DsRoleGetPrimaryDomainInformationDart = int Function(Pointer<Utf16>, int, Pointer<Uint8>);
final DsRoleGetPrimaryDomainInformation = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<DsRoleGetPrimaryDomainInformationNative, DsRoleGetPrimaryDomainInformationDart>('DsRoleGetPrimaryDomainInformation');
// lpServer : LPCWSTR -> Pointer<Utf16>
// InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> Int32
// Buffer : BYTE** in/out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DsRoleGetPrimaryDomainInformation(
  lpServer: PWideChar;   // LPCWSTR
  InfoLevel: Integer;   // DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
  Buffer: Pointer   // BYTE** in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DsRoleGetPrimaryDomainInformation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DsRoleGetPrimaryDomainInformation"
  c_DsRoleGetPrimaryDomainInformation :: CWString -> Int32 -> Ptr Word8 -> IO Word32
-- lpServer : LPCWSTR -> CWString
-- InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> Int32
-- Buffer : BYTE** in/out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dsrolegetprimarydomaininformation =
  foreign "DsRoleGetPrimaryDomainInformation"
    ((ptr uint16_t) @-> int32_t @-> (ptr uint8_t) @-> returning uint32_t)
(* lpServer : LPCWSTR -> (ptr uint16_t) *)
(* InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> int32_t *)
(* Buffer : BYTE** in/out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("DsRoleGetPrimaryDomainInformation" ds-role-get-primary-domain-information :convention :stdcall) :uint32
  (lp-server (:string :encoding :utf-16le))   ; LPCWSTR
  (info-level :int32)   ; DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
  (buffer :pointer))   ; BYTE** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DsRoleGetPrimaryDomainInformation = Win32::API::More->new('NETAPI32',
    'DWORD DsRoleGetPrimaryDomainInformation(LPCWSTR lpServer, int InfoLevel, LPVOID Buffer)');
# my $ret = $DsRoleGetPrimaryDomainInformation->Call($lpServer, $InfoLevel, $Buffer);
# lpServer : LPCWSTR -> LPCWSTR
# InfoLevel : DSROLE_PRIMARY_DOMAIN_INFO_LEVEL -> int
# Buffer : BYTE** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型