Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › GetComputerObjectNameA

GetComputerObjectNameA

関数
指定形式でローカルコンピューターのオブジェクト名を取得する(ANSI版)。
DLLSECUR32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOLEAN GetComputerObjectNameA(
    EXTENDED_NAME_FORMAT NameFormat,
    LPSTR lpNameBuffer,   // optional
    DWORD* nSize
);

パラメーター

名前方向
NameFormatEXTENDED_NAME_FORMATin
lpNameBufferLPSTRoutoptional
nSizeDWORD*inout

戻り値の型: BOOLEAN

各言語での呼び出し定義

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

BOOLEAN GetComputerObjectNameA(
    EXTENDED_NAME_FORMAT NameFormat,
    LPSTR lpNameBuffer,   // optional
    DWORD* nSize
);
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern byte GetComputerObjectNameA(
    int NameFormat,   // EXTENDED_NAME_FORMAT
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpNameBuffer,   // LPSTR optional, out
    ref uint nSize   // DWORD* in/out
);
<DllImport("SECUR32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetComputerObjectNameA(
    NameFormat As Integer,   ' EXTENDED_NAME_FORMAT
    <MarshalAs(UnmanagedType.LPStr)> lpNameBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    ByRef nSize As UInteger   ' DWORD* in/out
) As Byte
End Function
' NameFormat : EXTENDED_NAME_FORMAT
' lpNameBuffer : LPSTR optional, out
' nSize : DWORD* in/out
Declare PtrSafe Function GetComputerObjectNameA Lib "secur32" ( _
    ByVal NameFormat As Long, _
    ByVal lpNameBuffer As String, _
    ByRef nSize As Long) As Byte
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetComputerObjectNameA = ctypes.windll.secur32.GetComputerObjectNameA
GetComputerObjectNameA.restype = ctypes.c_byte
GetComputerObjectNameA.argtypes = [
    ctypes.c_int,  # NameFormat : EXTENDED_NAME_FORMAT
    wintypes.LPSTR,  # lpNameBuffer : LPSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # nSize : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SECUR32.dll')
GetComputerObjectNameA = Fiddle::Function.new(
  lib['GetComputerObjectNameA'],
  [
    Fiddle::TYPE_INT,  # NameFormat : EXTENDED_NAME_FORMAT
    Fiddle::TYPE_VOIDP,  # lpNameBuffer : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # nSize : DWORD* in/out
  ],
  Fiddle::TYPE_CHAR)
#[link(name = "secur32")]
extern "system" {
    fn GetComputerObjectNameA(
        NameFormat: i32,  // EXTENDED_NAME_FORMAT
        lpNameBuffer: *mut u8,  // LPSTR optional, out
        nSize: *mut u32  // DWORD* in/out
    ) -> u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern byte GetComputerObjectNameA(int NameFormat, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpNameBuffer, ref uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_GetComputerObjectNameA' -Namespace Win32 -PassThru
# $api::GetComputerObjectNameA(NameFormat, lpNameBuffer, nSize)
#uselib "SECUR32.dll"
#func global GetComputerObjectNameA "GetComputerObjectNameA" sptr, sptr, sptr
; GetComputerObjectNameA NameFormat, varptr(lpNameBuffer), varptr(nSize)   ; 戻り値は stat
; NameFormat : EXTENDED_NAME_FORMAT -> "sptr"
; lpNameBuffer : LPSTR optional, out -> "sptr"
; nSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SECUR32.dll"
#cfunc global GetComputerObjectNameA "GetComputerObjectNameA" int, var, var
; res = GetComputerObjectNameA(NameFormat, lpNameBuffer, nSize)
; NameFormat : EXTENDED_NAME_FORMAT -> "int"
; lpNameBuffer : LPSTR optional, out -> "var"
; nSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOLEAN GetComputerObjectNameA(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, DWORD* nSize)
#uselib "SECUR32.dll"
#cfunc global GetComputerObjectNameA "GetComputerObjectNameA" int, var, var
; res = GetComputerObjectNameA(NameFormat, lpNameBuffer, nSize)
; NameFormat : EXTENDED_NAME_FORMAT -> "int"
; lpNameBuffer : LPSTR optional, out -> "var"
; nSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procGetComputerObjectNameA = secur32.NewProc("GetComputerObjectNameA")
)

// NameFormat (EXTENDED_NAME_FORMAT), lpNameBuffer (LPSTR optional, out), nSize (DWORD* in/out)
r1, _, err := procGetComputerObjectNameA.Call(
	uintptr(NameFormat),
	uintptr(lpNameBuffer),
	uintptr(nSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOLEAN
function GetComputerObjectNameA(
  NameFormat: Integer;   // EXTENDED_NAME_FORMAT
  lpNameBuffer: PAnsiChar;   // LPSTR optional, out
  nSize: Pointer   // DWORD* in/out
): ByteBool; stdcall;
  external 'SECUR32.dll' name 'GetComputerObjectNameA';
result := DllCall("SECUR32\GetComputerObjectNameA"
    , "Int", NameFormat   ; EXTENDED_NAME_FORMAT
    , "Ptr", lpNameBuffer   ; LPSTR optional, out
    , "Ptr", nSize   ; DWORD* in/out
    , "Char")   ; return: BOOLEAN
●GetComputerObjectNameA(NameFormat, lpNameBuffer, nSize) = DLL("SECUR32.dll", "byte GetComputerObjectNameA(int, char*, void*)")
# 呼び出し: GetComputerObjectNameA(NameFormat, lpNameBuffer, nSize)
# NameFormat : EXTENDED_NAME_FORMAT -> "int"
# lpNameBuffer : LPSTR optional, out -> "char*"
# nSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。