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サイト名を問い合わせる対象コンピュータ名を指すANSI文字列。ローカルマシンの場合はNULL可。
SiteNameLPSTR*out取得したサイト名文字列へのポインタを受け取る出力。使用後はNetApiBufferFreeで解放する。

戻り値の型: 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)。
const std = @import("std");

extern "netapi32" fn DsGetSiteNameA(
    ComputerName: [*c]const u8, // LPCSTR optional
    SiteName: [*c][*c]u8 // LPSTR* out
) callconv(std.os.windows.WINAPI) u32;
proc DsGetSiteNameA(
    ComputerName: cstring,  # LPCSTR optional
    SiteName: ptr cstring  # LPSTR* out
): uint32 {.importc: "DsGetSiteNameA", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint DsGetSiteNameA(
    const(char)* ComputerName,   // LPCSTR optional
    char** SiteName   // LPSTR* out
);
ccall((:DsGetSiteNameA, "NETAPI32.dll"), stdcall, UInt32,
      (Cstring, Ptr{Ptr{UInt8}}),
      ComputerName, SiteName)
# ComputerName : LPCSTR optional -> Cstring
# SiteName : LPSTR* out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t DsGetSiteNameA(
    const char* ComputerName,
    char** SiteName);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.DsGetSiteNameA(ComputerName, SiteName)
-- ComputerName : LPCSTR optional
-- SiteName : LPSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const DsGetSiteNameA = lib.func('__stdcall', 'DsGetSiteNameA', 'uint32_t', ['str', 'void *']);
// DsGetSiteNameA(ComputerName, SiteName)
// ComputerName : LPCSTR optional -> 'str'
// SiteName : LPSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  DsGetSiteNameA: { parameters: ["buffer", "pointer"], result: "u32" },
});
// lib.symbols.DsGetSiteNameA(ComputerName, SiteName)
// ComputerName : LPCSTR optional -> "buffer"
// SiteName : LPSTR* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t DsGetSiteNameA(
    const char* ComputerName,
    char** SiteName);
C, "NETAPI32.dll");
// $ffi->DsGetSiteNameA(ComputerName, SiteName);
// ComputerName : LPCSTR optional
// SiteName : LPSTR* 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.ASCII_OPTIONS);
    int DsGetSiteNameA(
        String ComputerName,   // LPCSTR optional
        PointerByReference SiteName   // LPSTR* out
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun DsGetSiteNameA = DsGetSiteNameA(
    ComputerName : UInt8*,   # LPCSTR optional
    SiteName : UInt8**   # LPSTR* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DsGetSiteNameANative = Uint32 Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>);
typedef DsGetSiteNameADart = int Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>);
final DsGetSiteNameA = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<DsGetSiteNameANative, DsGetSiteNameADart>('DsGetSiteNameA');
// ComputerName : LPCSTR optional -> Pointer<Utf8>
// SiteName : LPSTR* out -> Pointer<Pointer<Utf8>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DsGetSiteNameA(
  ComputerName: PAnsiChar;   // LPCSTR optional
  SiteName: PPAnsiChar   // LPSTR* out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DsGetSiteNameA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

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

(cffi:defcfun ("DsGetSiteNameA" ds-get-site-name-a :convention :stdcall) :uint32
  (computer-name :string)   ; LPCSTR optional
  (site-name :pointer))   ; LPSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DsGetSiteNameA = Win32::API::More->new('NETAPI32',
    'DWORD DsGetSiteNameA(LPCSTR ComputerName, LPVOID SiteName)');
# my $ret = $DsGetSiteNameA->Call($ComputerName, $SiteName);
# ComputerName : LPCSTR optional -> LPCSTR
# SiteName : LPSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い