Win32 API 日本語リファレンス
ホームSystem.Performance › PdhConnectMachineW

PdhConnectMachineW

関数
リモートマシンへ接続しデータ収集を有効にする。
DLLpdh.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD PdhConnectMachineW(
    LPCWSTR szMachineName   // optional
);

パラメーター

名前方向
szMachineNameLPCWSTRinoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD PdhConnectMachineW(
    LPCWSTR szMachineName   // optional
);
[DllImport("pdh.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint PdhConnectMachineW(
    [MarshalAs(UnmanagedType.LPWStr)] string szMachineName   // LPCWSTR optional
);
<DllImport("pdh.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PdhConnectMachineW(
    <MarshalAs(UnmanagedType.LPWStr)> szMachineName As String   ' LPCWSTR optional
) As UInteger
End Function
' szMachineName : LPCWSTR optional
Declare PtrSafe Function PdhConnectMachineW Lib "pdh" ( _
    ByVal szMachineName 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

PdhConnectMachineW = ctypes.windll.pdh.PdhConnectMachineW
PdhConnectMachineW.restype = wintypes.DWORD
PdhConnectMachineW.argtypes = [
    wintypes.LPCWSTR,  # szMachineName : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('pdh.dll')
PdhConnectMachineW = Fiddle::Function.new(
  lib['PdhConnectMachineW'],
  [
    Fiddle::TYPE_VOIDP,  # szMachineName : LPCWSTR optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "pdh")]
extern "system" {
    fn PdhConnectMachineW(
        szMachineName: *const u16  // LPCWSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("pdh.dll", CharSet = CharSet.Unicode)]
public static extern uint PdhConnectMachineW([MarshalAs(UnmanagedType.LPWStr)] string szMachineName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhConnectMachineW' -Namespace Win32 -PassThru
# $api::PdhConnectMachineW(szMachineName)
#uselib "pdh.dll"
#func global PdhConnectMachineW "PdhConnectMachineW" wptr
; PdhConnectMachineW szMachineName   ; 戻り値は stat
; szMachineName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "pdh.dll"
#cfunc global PdhConnectMachineW "PdhConnectMachineW" wstr
; res = PdhConnectMachineW(szMachineName)
; szMachineName : LPCWSTR optional -> "wstr"
; DWORD PdhConnectMachineW(LPCWSTR szMachineName)
#uselib "pdh.dll"
#cfunc global PdhConnectMachineW "PdhConnectMachineW" wstr
; res = PdhConnectMachineW(szMachineName)
; szMachineName : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhConnectMachineW = pdh.NewProc("PdhConnectMachineW")
)

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