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

UnloadPerfCounterTextStringsW

関数
登録済みパフォーマンスカウンタのテキスト文字列を削除する。
DLLloadperf.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD UnloadPerfCounterTextStringsW(
    LPWSTR lpCommandLine,
    BOOL bQuietModeArg
);

パラメーター

名前方向説明
lpCommandLineLPWSTRin1 つ以上の任意の文字、スペース、そしてアプリケーション名で構成される、null で終わる文字列です。アプリケーション名は、テキスト文字列の読み込みに使用された初期化ファイル(.ini)内の drivername キーの値と一致している必要があります。
bQuietModeArgBOOLinUnlodctr ツールの出力を表示させたくない場合は TRUE に、それ以外の場合は FALSE に設定します。このパラメーターは、アプリケーションをコマンドプロンプトから実行した場合にのみ意味を持ちます。

戻り値の型: DWORD

公式ドキュメント

指定したアプリケーションのパフォーマンスオブジェクトとカウンターをコンピューターからアンロードします。(Unicode)

戻り値

関数が成功した場合、戻り値は ERROR_SUCCESS です。

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

解説(Remarks)

この関数は、Unlodctr ツールが提供する機能への API を提供します。詳細については、レジストリからのカウンター名と説明の削除を参照してください。

メモ

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

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

各言語での呼び出し定義

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

DWORD UnloadPerfCounterTextStringsW(
    LPWSTR lpCommandLine,
    BOOL bQuietModeArg
);
[DllImport("loadperf.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint UnloadPerfCounterTextStringsW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine,   // LPWSTR
    bool bQuietModeArg   // BOOL
);
<DllImport("loadperf.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function UnloadPerfCounterTextStringsW(
    <MarshalAs(UnmanagedType.LPWStr)> lpCommandLine As String,   ' LPWSTR
    bQuietModeArg As Boolean   ' BOOL
) As UInteger
End Function
' lpCommandLine : LPWSTR
' bQuietModeArg : BOOL
Declare PtrSafe Function UnloadPerfCounterTextStringsW 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

UnloadPerfCounterTextStringsW = ctypes.windll.loadperf.UnloadPerfCounterTextStringsW
UnloadPerfCounterTextStringsW.restype = wintypes.DWORD
UnloadPerfCounterTextStringsW.argtypes = [
    wintypes.LPCWSTR,  # lpCommandLine : LPWSTR
    wintypes.BOOL,  # bQuietModeArg : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('loadperf.dll')
UnloadPerfCounterTextStringsW = Fiddle::Function.new(
  lib['UnloadPerfCounterTextStringsW'],
  [
    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 UnloadPerfCounterTextStringsW(
        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 UnloadPerfCounterTextStringsW([MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, bool bQuietModeArg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'loadperf_UnloadPerfCounterTextStringsW' -Namespace Win32 -PassThru
# $api::UnloadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
#uselib "loadperf.dll"
#func global UnloadPerfCounterTextStringsW "UnloadPerfCounterTextStringsW" wptr, wptr
; UnloadPerfCounterTextStringsW lpCommandLine, bQuietModeArg   ; 戻り値は stat
; lpCommandLine : LPWSTR -> "wptr"
; bQuietModeArg : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "loadperf.dll"
#cfunc global UnloadPerfCounterTextStringsW "UnloadPerfCounterTextStringsW" wstr, int
; res = UnloadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPWSTR -> "wstr"
; bQuietModeArg : BOOL -> "int"
; DWORD UnloadPerfCounterTextStringsW(LPWSTR lpCommandLine, BOOL bQuietModeArg)
#uselib "loadperf.dll"
#cfunc global UnloadPerfCounterTextStringsW "UnloadPerfCounterTextStringsW" wstr, int
; res = UnloadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
; lpCommandLine : LPWSTR -> "wstr"
; bQuietModeArg : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	loadperf = windows.NewLazySystemDLL("loadperf.dll")
	procUnloadPerfCounterTextStringsW = loadperf.NewProc("UnloadPerfCounterTextStringsW")
)

// lpCommandLine (LPWSTR), bQuietModeArg (BOOL)
r1, _, err := procUnloadPerfCounterTextStringsW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCommandLine))),
	uintptr(bQuietModeArg),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function UnloadPerfCounterTextStringsW(
  lpCommandLine: PWideChar;   // LPWSTR
  bQuietModeArg: BOOL   // BOOL
): DWORD; stdcall;
  external 'loadperf.dll' name 'UnloadPerfCounterTextStringsW';
result := DllCall("loadperf\UnloadPerfCounterTextStringsW"
    , "WStr", lpCommandLine   ; LPWSTR
    , "Int", bQuietModeArg   ; BOOL
    , "UInt")   ; return: DWORD
●UnloadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg) = DLL("loadperf.dll", "dword UnloadPerfCounterTextStringsW(char*, bool)")
# 呼び出し: UnloadPerfCounterTextStringsW(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 UnloadPerfCounterTextStringsW(
    lpCommandLine: [*c]const u16, // LPWSTR
    bQuietModeArg: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc UnloadPerfCounterTextStringsW(
    lpCommandLine: WideCString,  # LPWSTR
    bQuietModeArg: int32  # BOOL
): uint32 {.importc: "UnloadPerfCounterTextStringsW", stdcall, dynlib: "loadperf.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "loadperf");
extern(Windows)
uint UnloadPerfCounterTextStringsW(
    const(wchar)* lpCommandLine,   // LPWSTR
    int bQuietModeArg   // BOOL
);
ccall((:UnloadPerfCounterTextStringsW, "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 UnloadPerfCounterTextStringsW(
    const uint16_t* lpCommandLine,
    int32_t bQuietModeArg);
]]
local loadperf = ffi.load("loadperf")
-- loadperf.UnloadPerfCounterTextStringsW(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 UnloadPerfCounterTextStringsW = lib.func('__stdcall', 'UnloadPerfCounterTextStringsW', 'uint32_t', ['str16', 'int32_t']);
// UnloadPerfCounterTextStringsW(lpCommandLine, bQuietModeArg)
// lpCommandLine : LPWSTR -> 'str16'
// bQuietModeArg : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("loadperf.dll", {
  UnloadPerfCounterTextStringsW: { parameters: ["buffer", "i32"], result: "u32" },
});
// lib.symbols.UnloadPerfCounterTextStringsW(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 UnloadPerfCounterTextStringsW(
    const uint16_t* lpCommandLine,
    int32_t bQuietModeArg);
C, "loadperf.dll");
// $ffi->UnloadPerfCounterTextStringsW(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 UnloadPerfCounterTextStringsW(
        WString lpCommandLine,   // LPWSTR
        boolean bQuietModeArg   // BOOL
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("loadperf")]
lib Libloadperf
  fun UnloadPerfCounterTextStringsW = UnloadPerfCounterTextStringsW(
    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 UnloadPerfCounterTextStringsWNative = Uint32 Function(Pointer<Utf16>, Int32);
typedef UnloadPerfCounterTextStringsWDart = int Function(Pointer<Utf16>, int);
final UnloadPerfCounterTextStringsW = DynamicLibrary.open('loadperf.dll')
    .lookupFunction<UnloadPerfCounterTextStringsWNative, UnloadPerfCounterTextStringsWDart>('UnloadPerfCounterTextStringsW');
// lpCommandLine : LPWSTR -> Pointer<Utf16>
// bQuietModeArg : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function UnloadPerfCounterTextStringsW(
  lpCommandLine: PWideChar;   // LPWSTR
  bQuietModeArg: BOOL   // BOOL
): DWORD; stdcall;
  external 'loadperf.dll' name 'UnloadPerfCounterTextStringsW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let unloadperfcountertextstringsw =
  foreign "UnloadPerfCounterTextStringsW"
    ((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 ("UnloadPerfCounterTextStringsW" unload-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 $UnloadPerfCounterTextStringsW = Win32::API::More->new('loadperf',
    'DWORD UnloadPerfCounterTextStringsW(LPCWSTR lpCommandLine, BOOL bQuietModeArg)');
# my $ret = $UnloadPerfCounterTextStringsW->Call($lpCommandLine, $bQuietModeArg);
# lpCommandLine : LPWSTR -> LPCWSTR
# bQuietModeArg : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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