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

LoadPerfCounterTextStringsA

関数
パフォーマンスカウンタの名称と説明テキストを登録する。ANSI版。
DLLloadperf.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD LoadPerfCounterTextStringsA(
    LPSTR lpCommandLine,
    BOOL bQuietModeArg
);

パラメーター

名前方向説明
lpCommandLineLPSTRin

1 つ以上の任意の文字、スペース、続いて初期化 (.ini) ファイルの名前で構成される、null で終わる文字列です。名前には初期化ファイルへのパスを含めることができます。

この関数は初期化ファイルのみを使用し、最初の引数は破棄されます。たとえば、"myfile.ini" という初期化ファイルを読み込むには、commandLine 文字列を "xx myfile.ini" のようにします。スペースより前の文字 (ここでは "xx") は破棄され、スペースに続く 2 番目の部分が初期化ファイルの指定として解釈されます。

bQuietModeArgBOOLinLodctr ツールの出力を関数が表示しないようにするには TRUE を設定します。それ以外の場合は FALSE です。このパラメーターは、アプリケーションがコマンド プロンプトから実行された場合にのみ意味を持ちます。

戻り値の型: DWORD

公式ドキュメント

指定された初期化ファイルで定義されたパフォーマンス オブジェクトおよびカウンターをコンピューターに読み込みます。(ANSI)

戻り値

関数が成功した場合は ERROR_SUCCESS を返します。

関数が失敗した場合、戻り値は システム エラー コード のいずれかです。

解説(Remarks)

この関数は、Lodctr ツールが提供する機能への API を提供します。Lodctr の詳細については、Adding Counter Names and Descriptions to the Registry を参照してください。

メモ

loadperf.h ヘッダーは、LoadPerfCounterTextStrings をエイリアスとして定義します。これは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコード ニュートラルなエイリアスの使用を、エンコード ニュートラルでないコードと混在させると、コンパイル エラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD LoadPerfCounterTextStringsA(
    LPSTR lpCommandLine,
    BOOL bQuietModeArg
);
[DllImport("loadperf.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint LoadPerfCounterTextStringsA(
    [MarshalAs(UnmanagedType.LPStr)] string lpCommandLine,   // LPSTR
    bool bQuietModeArg   // BOOL
);
<DllImport("loadperf.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function LoadPerfCounterTextStringsA(
    <MarshalAs(UnmanagedType.LPStr)> lpCommandLine As String,   ' LPSTR
    bQuietModeArg As Boolean   ' BOOL
) As UInteger
End Function
' lpCommandLine : LPSTR
' bQuietModeArg : BOOL
Declare PtrSafe Function LoadPerfCounterTextStringsA Lib "loadperf" ( _
    ByVal lpCommandLine As String, _
    ByVal bQuietModeArg As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadPerfCounterTextStringsA = ctypes.windll.loadperf.LoadPerfCounterTextStringsA
LoadPerfCounterTextStringsA.restype = wintypes.DWORD
LoadPerfCounterTextStringsA.argtypes = [
    wintypes.LPCSTR,  # lpCommandLine : LPSTR
    wintypes.BOOL,  # bQuietModeArg : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('loadperf.dll')
LoadPerfCounterTextStringsA = Fiddle::Function.new(
  lib['LoadPerfCounterTextStringsA'],
  [
    Fiddle::TYPE_VOIDP,  # lpCommandLine : LPSTR
    Fiddle::TYPE_INT,  # bQuietModeArg : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "loadperf")]
extern "system" {
    fn LoadPerfCounterTextStringsA(
        lpCommandLine: *mut u8,  // LPSTR
        bQuietModeArg: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("loadperf.dll", CharSet = CharSet.Ansi)]
public static extern uint LoadPerfCounterTextStringsA([MarshalAs(UnmanagedType.LPStr)] string lpCommandLine, bool bQuietModeArg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'loadperf_LoadPerfCounterTextStringsA' -Namespace Win32 -PassThru
# $api::LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
#uselib "loadperf.dll"
#func global LoadPerfCounterTextStringsA "LoadPerfCounterTextStringsA" sptr, sptr
; LoadPerfCounterTextStringsA lpCommandLine, bQuietModeArg   ; 戻り値は stat
; lpCommandLine : LPSTR -> "sptr"
; bQuietModeArg : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "loadperf.dll"
#cfunc global LoadPerfCounterTextStringsA "LoadPerfCounterTextStringsA" str, int
; res = LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPSTR -> "str"
; bQuietModeArg : BOOL -> "int"
; DWORD LoadPerfCounterTextStringsA(LPSTR lpCommandLine, BOOL bQuietModeArg)
#uselib "loadperf.dll"
#cfunc global LoadPerfCounterTextStringsA "LoadPerfCounterTextStringsA" str, int
; res = LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPSTR -> "str"
; bQuietModeArg : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	loadperf = windows.NewLazySystemDLL("loadperf.dll")
	procLoadPerfCounterTextStringsA = loadperf.NewProc("LoadPerfCounterTextStringsA")
)

// lpCommandLine (LPSTR), bQuietModeArg (BOOL)
r1, _, err := procLoadPerfCounterTextStringsA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpCommandLine))),
	uintptr(bQuietModeArg),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function LoadPerfCounterTextStringsA(
  lpCommandLine: PAnsiChar;   // LPSTR
  bQuietModeArg: BOOL   // BOOL
): DWORD; stdcall;
  external 'loadperf.dll' name 'LoadPerfCounterTextStringsA';
result := DllCall("loadperf\LoadPerfCounterTextStringsA"
    , "AStr", lpCommandLine   ; LPSTR
    , "Int", bQuietModeArg   ; BOOL
    , "UInt")   ; return: DWORD
●LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg) = DLL("loadperf.dll", "dword LoadPerfCounterTextStringsA(char*, bool)")
# 呼び出し: LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
# lpCommandLine : LPSTR -> "char*"
# bQuietModeArg : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "loadperf" fn LoadPerfCounterTextStringsA(
    lpCommandLine: [*c]const u8, // LPSTR
    bQuietModeArg: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
proc LoadPerfCounterTextStringsA(
    lpCommandLine: cstring,  # LPSTR
    bQuietModeArg: int32  # BOOL
): uint32 {.importc: "LoadPerfCounterTextStringsA", stdcall, dynlib: "loadperf.dll".}
pragma(lib, "loadperf");
extern(Windows)
uint LoadPerfCounterTextStringsA(
    const(char)* lpCommandLine,   // LPSTR
    int bQuietModeArg   // BOOL
);
ccall((:LoadPerfCounterTextStringsA, "loadperf.dll"), stdcall, UInt32,
      (Cstring, Int32),
      lpCommandLine, bQuietModeArg)
# lpCommandLine : LPSTR -> Cstring
# bQuietModeArg : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t LoadPerfCounterTextStringsA(
    const char* lpCommandLine,
    int32_t bQuietModeArg);
]]
local loadperf = ffi.load("loadperf")
-- loadperf.LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
-- lpCommandLine : LPSTR
-- bQuietModeArg : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('loadperf.dll');
const LoadPerfCounterTextStringsA = lib.func('__stdcall', 'LoadPerfCounterTextStringsA', 'uint32_t', ['str', 'int32_t']);
// LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
// lpCommandLine : LPSTR -> 'str'
// bQuietModeArg : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("loadperf.dll", {
  LoadPerfCounterTextStringsA: { parameters: ["buffer", "i32"], result: "u32" },
});
// lib.symbols.LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg)
// lpCommandLine : LPSTR -> "buffer"
// bQuietModeArg : BOOL -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t LoadPerfCounterTextStringsA(
    const char* lpCommandLine,
    int32_t bQuietModeArg);
C, "loadperf.dll");
// $ffi->LoadPerfCounterTextStringsA(lpCommandLine, bQuietModeArg);
// lpCommandLine : LPSTR
// 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.ASCII_OPTIONS);
    int LoadPerfCounterTextStringsA(
        String lpCommandLine,   // LPSTR
        boolean bQuietModeArg   // BOOL
    );
}
@[Link("loadperf")]
lib Libloadperf
  fun LoadPerfCounterTextStringsA = LoadPerfCounterTextStringsA(
    lpCommandLine : UInt8*,   # LPSTR
    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 LoadPerfCounterTextStringsANative = Uint32 Function(Pointer<Utf8>, Int32);
typedef LoadPerfCounterTextStringsADart = int Function(Pointer<Utf8>, int);
final LoadPerfCounterTextStringsA = DynamicLibrary.open('loadperf.dll')
    .lookupFunction<LoadPerfCounterTextStringsANative, LoadPerfCounterTextStringsADart>('LoadPerfCounterTextStringsA');
// lpCommandLine : LPSTR -> Pointer<Utf8>
// bQuietModeArg : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function LoadPerfCounterTextStringsA(
  lpCommandLine: PAnsiChar;   // LPSTR
  bQuietModeArg: BOOL   // BOOL
): DWORD; stdcall;
  external 'loadperf.dll' name 'LoadPerfCounterTextStringsA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "LoadPerfCounterTextStringsA"
  c_LoadPerfCounterTextStringsA :: CString -> CInt -> IO Word32
-- lpCommandLine : LPSTR -> CString
-- bQuietModeArg : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let loadperfcountertextstringsa =
  foreign "LoadPerfCounterTextStringsA"
    (string @-> int32_t @-> returning uint32_t)
(* lpCommandLine : LPSTR -> string *)
(* 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 ("LoadPerfCounterTextStringsA" load-perf-counter-text-strings-a :convention :stdcall) :uint32
  (lp-command-line :string)   ; LPSTR
  (b-quiet-mode-arg :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $LoadPerfCounterTextStringsA = Win32::API::More->new('loadperf',
    'DWORD LoadPerfCounterTextStringsA(LPCSTR lpCommandLine, BOOL bQuietModeArg)');
# my $ret = $LoadPerfCounterTextStringsA->Call($lpCommandLine, $bQuietModeArg);
# lpCommandLine : LPSTR -> LPCSTR
# bQuietModeArg : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目