LoadPerfCounterTextStringsW
関数シグネチャ
// loadperf.dll (Unicode / -W)
#include <windows.h>
DWORD LoadPerfCounterTextStringsW(
LPWSTR lpCommandLine,
BOOL bQuietModeArg
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpCommandLine | LPWSTR | in | 1 つ以上の任意の文字、空白、その後に初期化 (.ini) ファイル名が続く、null 終端文字列です。名前には初期化ファイルへのパスを含めることができます。 この関数は初期化ファイルのみを使用し、最初の引数は破棄されます。たとえば、"myfile.ini" という初期化ファイルを読み込むには、commandLine 文字列を "xx myfile.ini" とします。空白より前の文字 (ここでは "xx") は破棄され、空白に続く 2 番目の部分が初期化ファイルの指定として解釈されます。 |
| bQuietModeArg | BOOL | in | Lodctr ツールの出力を表示しないようにするには TRUE を、それ以外の場合は FALSE を設定します。このパラメーターは、アプリケーションがコマンドプロンプトから実行された場合にのみ意味を持ちます。 |
戻り値の型: DWORD
公式ドキュメント
指定された初期化ファイルで定義されたパフォーマンスオブジェクトとカウンターをコンピューターに読み込みます。(Unicode)
戻り値
関数が成功した場合は ERROR_SUCCESS を返します。
関数が失敗した場合、戻り値は システムエラーコードのいずれかになります。
解説(Remarks)
この関数は、Lodctr ツールが提供する機能への API を提供します。Lodctr の詳細については、Adding Counter Names and Descriptions to the Registry を参照してください。
loadperf.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして LoadPerfCounterTextStrings を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// loadperf.dll (Unicode / -W)
#include <windows.h>
DWORD LoadPerfCounterTextStringsW(
LPWSTR lpCommandLine,
BOOL bQuietModeArg
);[DllImport("loadperf.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint LoadPerfCounterTextStringsW(
[MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, // LPWSTR
bool bQuietModeArg // BOOL
);<DllImport("loadperf.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function LoadPerfCounterTextStringsW(
<MarshalAs(UnmanagedType.LPWStr)> lpCommandLine As String, ' LPWSTR
bQuietModeArg As Boolean ' BOOL
) As UInteger
End Function' lpCommandLine : LPWSTR
' bQuietModeArg : BOOL
Declare PtrSafe Function LoadPerfCounterTextStringsW Lib "loadperf" ( _
ByVal lpCommandLine As LongPtr, _
ByVal bQuietModeArg As Long) 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
LoadPerfCounterTextStringsW = ctypes.windll.loadperf.LoadPerfCounterTextStringsW
LoadPerfCounterTextStringsW.restype = wintypes.DWORD
LoadPerfCounterTextStringsW.argtypes = [
wintypes.LPCWSTR, # lpCommandLine : LPWSTR
wintypes.BOOL, # bQuietModeArg : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('loadperf.dll')
LoadPerfCounterTextStringsW = Fiddle::Function.new(
lib['LoadPerfCounterTextStringsW'],
[
Fiddle::TYPE_VOIDP, # lpCommandLine : LPWSTR
Fiddle::TYPE_INT, # bQuietModeArg : BOOL
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "loadperf")]
extern "system" {
fn LoadPerfCounterTextStringsW(
lpCommandLine: *mut u16, // LPWSTR
bQuietModeArg: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("loadperf.dll", CharSet = CharSet.Unicode)]
public static extern uint LoadPerfCounterTextStringsW([MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, bool bQuietModeArg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'loadperf_LoadPerfCounterTextStringsW' -Namespace Win32 -PassThru
# $api::LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)#uselib "loadperf.dll"
#func global LoadPerfCounterTextStringsW "LoadPerfCounterTextStringsW" wptr, wptr
; LoadPerfCounterTextStringsW lpCommandLine, bQuietModeArg ; 戻り値は stat
; lpCommandLine : LPWSTR -> "wptr"
; bQuietModeArg : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "loadperf.dll"
#cfunc global LoadPerfCounterTextStringsW "LoadPerfCounterTextStringsW" wstr, int
; res = LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPWSTR -> "wstr"
; bQuietModeArg : BOOL -> "int"; DWORD LoadPerfCounterTextStringsW(LPWSTR lpCommandLine, BOOL bQuietModeArg)
#uselib "loadperf.dll"
#cfunc global LoadPerfCounterTextStringsW "LoadPerfCounterTextStringsW" wstr, int
; res = LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPWSTR -> "wstr"
; bQuietModeArg : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
loadperf = windows.NewLazySystemDLL("loadperf.dll")
procLoadPerfCounterTextStringsW = loadperf.NewProc("LoadPerfCounterTextStringsW")
)
// lpCommandLine (LPWSTR), bQuietModeArg (BOOL)
r1, _, err := procLoadPerfCounterTextStringsW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCommandLine))),
uintptr(bQuietModeArg),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction LoadPerfCounterTextStringsW(
lpCommandLine: PWideChar; // LPWSTR
bQuietModeArg: BOOL // BOOL
): DWORD; stdcall;
external 'loadperf.dll' name 'LoadPerfCounterTextStringsW';result := DllCall("loadperf\LoadPerfCounterTextStringsW"
, "WStr", lpCommandLine ; LPWSTR
, "Int", bQuietModeArg ; BOOL
, "UInt") ; return: DWORD●LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg) = DLL("loadperf.dll", "dword LoadPerfCounterTextStringsW(char*, bool)")
# 呼び出し: LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
# lpCommandLine : LPWSTR -> "char*"
# bQuietModeArg : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "loadperf" fn LoadPerfCounterTextStringsW(
lpCommandLine: [*c]const u16, // LPWSTR
bQuietModeArg: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc LoadPerfCounterTextStringsW(
lpCommandLine: WideCString, # LPWSTR
bQuietModeArg: int32 # BOOL
): uint32 {.importc: "LoadPerfCounterTextStringsW", stdcall, dynlib: "loadperf.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "loadperf");
extern(Windows)
uint LoadPerfCounterTextStringsW(
const(wchar)* lpCommandLine, // LPWSTR
int bQuietModeArg // BOOL
);ccall((:LoadPerfCounterTextStringsW, "loadperf.dll"), stdcall, UInt32,
(Cwstring, Int32),
lpCommandLine, bQuietModeArg)
# lpCommandLine : LPWSTR -> Cwstring
# bQuietModeArg : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t LoadPerfCounterTextStringsW(
const uint16_t* lpCommandLine,
int32_t bQuietModeArg);
]]
local loadperf = ffi.load("loadperf")
-- loadperf.LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
-- lpCommandLine : LPWSTR
-- bQuietModeArg : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('loadperf.dll');
const LoadPerfCounterTextStringsW = lib.func('__stdcall', 'LoadPerfCounterTextStringsW', 'uint32_t', ['str16', 'int32_t']);
// LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
// lpCommandLine : LPWSTR -> 'str16'
// bQuietModeArg : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("loadperf.dll", {
LoadPerfCounterTextStringsW: { parameters: ["buffer", "i32"], result: "u32" },
});
// lib.symbols.LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
// lpCommandLine : LPWSTR -> "buffer"
// bQuietModeArg : BOOL -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t LoadPerfCounterTextStringsW(
const uint16_t* lpCommandLine,
int32_t bQuietModeArg);
C, "loadperf.dll");
// $ffi->LoadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg);
// lpCommandLine : LPWSTR
// bQuietModeArg : BOOL
// 構造体/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 Loadperf extends StdCallLibrary {
Loadperf INSTANCE = Native.load("loadperf", Loadperf.class, W32APIOptions.UNICODE_OPTIONS);
int LoadPerfCounterTextStringsW(
WString lpCommandLine, // LPWSTR
boolean bQuietModeArg // BOOL
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("loadperf")]
lib Libloadperf
fun LoadPerfCounterTextStringsW = LoadPerfCounterTextStringsW(
lpCommandLine : UInt16*, # LPWSTR
bQuietModeArg : Int32 # BOOL
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LoadPerfCounterTextStringsWNative = Uint32 Function(Pointer<Utf16>, Int32);
typedef LoadPerfCounterTextStringsWDart = int Function(Pointer<Utf16>, int);
final LoadPerfCounterTextStringsW = DynamicLibrary.open('loadperf.dll')
.lookupFunction<LoadPerfCounterTextStringsWNative, LoadPerfCounterTextStringsWDart>('LoadPerfCounterTextStringsW');
// lpCommandLine : LPWSTR -> Pointer<Utf16>
// bQuietModeArg : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LoadPerfCounterTextStringsW(
lpCommandLine: PWideChar; // LPWSTR
bQuietModeArg: BOOL // BOOL
): DWORD; stdcall;
external 'loadperf.dll' name 'LoadPerfCounterTextStringsW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LoadPerfCounterTextStringsW"
c_LoadPerfCounterTextStringsW :: CWString -> CInt -> IO Word32
-- lpCommandLine : LPWSTR -> CWString
-- bQuietModeArg : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let loadperfcountertextstringsw =
foreign "LoadPerfCounterTextStringsW"
((ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* lpCommandLine : LPWSTR -> (ptr uint16_t) *)
(* bQuietModeArg : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library loadperf (t "loadperf.dll"))
(cffi:use-foreign-library loadperf)
(cffi:defcfun ("LoadPerfCounterTextStringsW" load-perf-counter-text-strings-w :convention :stdcall) :uint32
(lp-command-line (:string :encoding :utf-16le)) ; LPWSTR
(b-quiet-mode-arg :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LoadPerfCounterTextStringsW = Win32::API::More->new('loadperf',
'DWORD LoadPerfCounterTextStringsW(LPCWSTR lpCommandLine, BOOL bQuietModeArg)');
# my $ret = $LoadPerfCounterTextStringsW->Call($lpCommandLine, $bQuietModeArg);
# lpCommandLine : LPWSTR -> LPCWSTR
# bQuietModeArg : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f LoadPerfCounterTextStringsA (ANSI版) — パフォーマンスカウンタの名称と説明テキストを登録する。ANSI版。
- f UnloadPerfCounterTextStringsW — 登録済みパフォーマンスカウンタのテキスト文字列を削除する。