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

DsGetSiteNameA

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

シグネチャ

// NETAPI32.dll  (ANSI / -A)
#include <windows.h>

DWORD DsGetSiteNameA(
    LPCSTR ComputerName,   // optional
    LPSTR* SiteName
);

パラメーター

名前方向
ComputerNameLPCSTRinoptional
SiteNameLPSTR*out

戻り値の型: DWORD

各言語での呼び出し定義

// NETAPI32.dll  (ANSI / -A)
#include <windows.h>

DWORD DsGetSiteNameA(
    LPCSTR ComputerName,   // optional
    LPSTR* SiteName
);
[DllImport("NETAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsGetSiteNameA(
    [MarshalAs(UnmanagedType.LPStr)] string ComputerName,   // LPCSTR optional
    IntPtr SiteName   // LPSTR* out
);
<DllImport("NETAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsGetSiteNameA(
    <MarshalAs(UnmanagedType.LPStr)> ComputerName As String,   ' LPCSTR optional
    SiteName As IntPtr   ' LPSTR* out
) As UInteger
End Function
' ComputerName : LPCSTR optional
' SiteName : LPSTR* out
Declare PtrSafe Function DsGetSiteNameA Lib "netapi32" ( _
    ByVal ComputerName As String, _
    ByVal SiteName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procDsGetSiteNameA = netapi32.NewProc("DsGetSiteNameA")
)

// ComputerName (LPCSTR optional), SiteName (LPSTR* out)
r1, _, err := procDsGetSiteNameA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ComputerName))),
	uintptr(SiteName),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsGetSiteNameA(
  ComputerName: PAnsiChar;   // LPCSTR optional
  SiteName: PPAnsiChar   // LPSTR* out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DsGetSiteNameA';
result := DllCall("NETAPI32\DsGetSiteNameA"
    , "AStr", ComputerName   ; LPCSTR optional
    , "Ptr", SiteName   ; LPSTR* out
    , "UInt")   ; return: DWORD
●DsGetSiteNameA(ComputerName, SiteName) = DLL("NETAPI32.dll", "dword DsGetSiteNameA(char*, void*)")
# 呼び出し: DsGetSiteNameA(ComputerName, SiteName)
# ComputerName : LPCSTR optional -> "char*"
# SiteName : LPSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。