ホーム › System.SystemInformation › SetComputerNameA
SetComputerNameA
関数コンピューター名を設定する(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetComputerNameA(
LPCSTR lpComputerName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpComputerName | LPCSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetComputerNameA(
LPCSTR lpComputerName
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetComputerNameA(
[MarshalAs(UnmanagedType.LPStr)] string lpComputerName // LPCSTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetComputerNameA(
<MarshalAs(UnmanagedType.LPStr)> lpComputerName As String ' LPCSTR
) As Boolean
End Function' lpComputerName : LPCSTR
Declare PtrSafe Function SetComputerNameA Lib "kernel32" ( _
ByVal lpComputerName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetComputerNameA = ctypes.windll.kernel32.SetComputerNameA
SetComputerNameA.restype = wintypes.BOOL
SetComputerNameA.argtypes = [
wintypes.LPCSTR, # lpComputerName : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetComputerNameA = Fiddle::Function.new(
lib['SetComputerNameA'],
[
Fiddle::TYPE_VOIDP, # lpComputerName : LPCSTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetComputerNameA(
lpComputerName: *const u8 // LPCSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetComputerNameA([MarshalAs(UnmanagedType.LPStr)] string lpComputerName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetComputerNameA' -Namespace Win32 -PassThru
# $api::SetComputerNameA(lpComputerName)#uselib "KERNEL32.dll"
#func global SetComputerNameA "SetComputerNameA" sptr
; SetComputerNameA lpComputerName ; 戻り値は stat
; lpComputerName : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetComputerNameA "SetComputerNameA" str
; res = SetComputerNameA(lpComputerName)
; lpComputerName : LPCSTR -> "str"; BOOL SetComputerNameA(LPCSTR lpComputerName)
#uselib "KERNEL32.dll"
#cfunc global SetComputerNameA "SetComputerNameA" str
; res = SetComputerNameA(lpComputerName)
; lpComputerName : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetComputerNameA = kernel32.NewProc("SetComputerNameA")
)
// lpComputerName (LPCSTR)
r1, _, err := procSetComputerNameA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpComputerName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetComputerNameA(
lpComputerName: PAnsiChar // LPCSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetComputerNameA';result := DllCall("KERNEL32\SetComputerNameA"
, "AStr", lpComputerName ; LPCSTR
, "Int") ; return: BOOL●SetComputerNameA(lpComputerName) = DLL("KERNEL32.dll", "bool SetComputerNameA(char*)")
# 呼び出し: SetComputerNameA(lpComputerName)
# lpComputerName : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。