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

DsGetSiteNameW

関数
指定コンピューターが属するサイト名を取得する。
DLLNETAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsGetSiteNameW(
    LPCWSTR ComputerName,   // optional
    LPWSTR* SiteName
);

パラメーター

名前方向説明
ComputerNameLPCWSTRinoptionalサイト名を問い合わせる対象コンピュータ名を指すワイド文字列。ローカルマシンの場合はNULL可。
SiteNameLPWSTR*out取得したサイト名文字列へのポインタを受け取る出力。使用後はNetApiBufferFreeで解放する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsGetSiteNameW(
    LPCWSTR ComputerName,   // optional
    LPWSTR* SiteName
);
[DllImport("NETAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsGetSiteNameW(
    [MarshalAs(UnmanagedType.LPWStr)] string ComputerName,   // LPCWSTR optional
    IntPtr SiteName   // LPWSTR* out
);
<DllImport("NETAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsGetSiteNameW(
    <MarshalAs(UnmanagedType.LPWStr)> ComputerName As String,   ' LPCWSTR optional
    SiteName As IntPtr   ' LPWSTR* out
) As UInteger
End Function
' ComputerName : LPCWSTR optional
' SiteName : LPWSTR* out
Declare PtrSafe Function DsGetSiteNameW Lib "netapi32" ( _
    ByVal ComputerName As LongPtr, _
    ByVal SiteName 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

DsGetSiteNameW = ctypes.windll.netapi32.DsGetSiteNameW
DsGetSiteNameW.restype = wintypes.DWORD
DsGetSiteNameW.argtypes = [
    wintypes.LPCWSTR,  # ComputerName : LPCWSTR optional
    ctypes.c_void_p,  # SiteName : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procDsGetSiteNameW = netapi32.NewProc("DsGetSiteNameW")
)

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

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

typedef DsGetSiteNameWNative = Uint32 Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
typedef DsGetSiteNameWDart = int Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
final DsGetSiteNameW = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<DsGetSiteNameWNative, DsGetSiteNameWDart>('DsGetSiteNameW');
// ComputerName : LPCWSTR optional -> Pointer<Utf16>
// SiteName : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DsGetSiteNameW(
  ComputerName: PWideChar;   // LPCWSTR optional
  SiteName: PPWideChar   // LPWSTR* out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DsGetSiteNameW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DsGetSiteNameW"
  c_DsGetSiteNameW :: CWString -> Ptr CWString -> IO Word32
-- ComputerName : LPCWSTR optional -> CWString
-- SiteName : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dsgetsitenamew =
  foreign "DsGetSiteNameW"
    ((ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> returning uint32_t)
(* ComputerName : LPCWSTR optional -> (ptr uint16_t) *)
(* SiteName : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("DsGetSiteNameW" ds-get-site-name-w :convention :stdcall) :uint32
  (computer-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (site-name :pointer))   ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DsGetSiteNameW = Win32::API::More->new('NETAPI32',
    'DWORD DsGetSiteNameW(LPCWSTR ComputerName, LPVOID SiteName)');
# my $ret = $DsGetSiteNameW->Call($ComputerName, $SiteName);
# ComputerName : LPCWSTR optional -> LPCWSTR
# SiteName : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い