ホーム › System.Performance › SetServiceAsTrustedW
SetServiceAsTrustedW
関数パフォーマンス収集で信頼済みとなるようサービスを設定する。
シグネチャ
// loadperf.dll (Unicode / -W)
#include <windows.h>
DWORD SetServiceAsTrustedW(
LPCWSTR szReserved, // optional
LPCWSTR szServiceName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szReserved | LPCWSTR | inoptional | 予約済みパラメータ。NULLを指定する。 |
| szServiceName | LPCWSTR | in | 信頼済みとして設定するサービス名。 |
戻り値の型: DWORD
各言語での呼び出し定義
// loadperf.dll (Unicode / -W)
#include <windows.h>
DWORD SetServiceAsTrustedW(
LPCWSTR szReserved, // optional
LPCWSTR szServiceName
);[DllImport("loadperf.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SetServiceAsTrustedW(
[MarshalAs(UnmanagedType.LPWStr)] string szReserved, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string szServiceName // LPCWSTR
);<DllImport("loadperf.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SetServiceAsTrustedW(
<MarshalAs(UnmanagedType.LPWStr)> szReserved As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> szServiceName As String ' LPCWSTR
) As UInteger
End Function' szReserved : LPCWSTR optional
' szServiceName : LPCWSTR
Declare PtrSafe Function SetServiceAsTrustedW Lib "loadperf" ( _
ByVal szReserved As LongPtr, _
ByVal szServiceName 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
SetServiceAsTrustedW = ctypes.windll.loadperf.SetServiceAsTrustedW
SetServiceAsTrustedW.restype = wintypes.DWORD
SetServiceAsTrustedW.argtypes = [
wintypes.LPCWSTR, # szReserved : LPCWSTR optional
wintypes.LPCWSTR, # szServiceName : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('loadperf.dll')
SetServiceAsTrustedW = Fiddle::Function.new(
lib['SetServiceAsTrustedW'],
[
Fiddle::TYPE_VOIDP, # szReserved : LPCWSTR optional
Fiddle::TYPE_VOIDP, # szServiceName : LPCWSTR
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "loadperf")]
extern "system" {
fn SetServiceAsTrustedW(
szReserved: *const u16, // LPCWSTR optional
szServiceName: *const u16 // LPCWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("loadperf.dll", CharSet = CharSet.Unicode)]
public static extern uint SetServiceAsTrustedW([MarshalAs(UnmanagedType.LPWStr)] string szReserved, [MarshalAs(UnmanagedType.LPWStr)] string szServiceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'loadperf_SetServiceAsTrustedW' -Namespace Win32 -PassThru
# $api::SetServiceAsTrustedW(szReserved, szServiceName)#uselib "loadperf.dll"
#func global SetServiceAsTrustedW "SetServiceAsTrustedW" wptr, wptr
; SetServiceAsTrustedW szReserved, szServiceName ; 戻り値は stat
; szReserved : LPCWSTR optional -> "wptr"
; szServiceName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "loadperf.dll"
#cfunc global SetServiceAsTrustedW "SetServiceAsTrustedW" wstr, wstr
; res = SetServiceAsTrustedW(szReserved, szServiceName)
; szReserved : LPCWSTR optional -> "wstr"
; szServiceName : LPCWSTR -> "wstr"; DWORD SetServiceAsTrustedW(LPCWSTR szReserved, LPCWSTR szServiceName)
#uselib "loadperf.dll"
#cfunc global SetServiceAsTrustedW "SetServiceAsTrustedW" wstr, wstr
; res = SetServiceAsTrustedW(szReserved, szServiceName)
; szReserved : LPCWSTR optional -> "wstr"
; szServiceName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
loadperf = windows.NewLazySystemDLL("loadperf.dll")
procSetServiceAsTrustedW = loadperf.NewProc("SetServiceAsTrustedW")
)
// szReserved (LPCWSTR optional), szServiceName (LPCWSTR)
r1, _, err := procSetServiceAsTrustedW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szReserved))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szServiceName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SetServiceAsTrustedW(
szReserved: PWideChar; // LPCWSTR optional
szServiceName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'loadperf.dll' name 'SetServiceAsTrustedW';result := DllCall("loadperf\SetServiceAsTrustedW"
, "WStr", szReserved ; LPCWSTR optional
, "WStr", szServiceName ; LPCWSTR
, "UInt") ; return: DWORD●SetServiceAsTrustedW(szReserved, szServiceName) = DLL("loadperf.dll", "dword SetServiceAsTrustedW(char*, char*)")
# 呼び出し: SetServiceAsTrustedW(szReserved, szServiceName)
# szReserved : LPCWSTR optional -> "char*"
# szServiceName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "loadperf" fn SetServiceAsTrustedW(
szReserved: [*c]const u16, // LPCWSTR optional
szServiceName: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetServiceAsTrustedW(
szReserved: WideCString, # LPCWSTR optional
szServiceName: WideCString # LPCWSTR
): uint32 {.importc: "SetServiceAsTrustedW", stdcall, dynlib: "loadperf.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "loadperf");
extern(Windows)
uint SetServiceAsTrustedW(
const(wchar)* szReserved, // LPCWSTR optional
const(wchar)* szServiceName // LPCWSTR
);ccall((:SetServiceAsTrustedW, "loadperf.dll"), stdcall, UInt32,
(Cwstring, Cwstring),
szReserved, szServiceName)
# szReserved : LPCWSTR optional -> Cwstring
# szServiceName : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t SetServiceAsTrustedW(
const uint16_t* szReserved,
const uint16_t* szServiceName);
]]
local loadperf = ffi.load("loadperf")
-- loadperf.SetServiceAsTrustedW(szReserved, szServiceName)
-- szReserved : LPCWSTR optional
-- szServiceName : LPCWSTR
-- 構造体/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 SetServiceAsTrustedW = lib.func('__stdcall', 'SetServiceAsTrustedW', 'uint32_t', ['str16', 'str16']);
// SetServiceAsTrustedW(szReserved, szServiceName)
// szReserved : LPCWSTR optional -> 'str16'
// szServiceName : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("loadperf.dll", {
SetServiceAsTrustedW: { parameters: ["buffer", "buffer"], result: "u32" },
});
// lib.symbols.SetServiceAsTrustedW(szReserved, szServiceName)
// szReserved : LPCWSTR optional -> "buffer"
// szServiceName : LPCWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SetServiceAsTrustedW(
const uint16_t* szReserved,
const uint16_t* szServiceName);
C, "loadperf.dll");
// $ffi->SetServiceAsTrustedW(szReserved, szServiceName);
// szReserved : LPCWSTR optional
// szServiceName : LPCWSTR
// 構造体/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 SetServiceAsTrustedW(
WString szReserved, // LPCWSTR optional
WString szServiceName // LPCWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("loadperf")]
lib Libloadperf
fun SetServiceAsTrustedW = SetServiceAsTrustedW(
szReserved : UInt16*, # LPCWSTR optional
szServiceName : UInt16* # LPCWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetServiceAsTrustedWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef SetServiceAsTrustedWDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final SetServiceAsTrustedW = DynamicLibrary.open('loadperf.dll')
.lookupFunction<SetServiceAsTrustedWNative, SetServiceAsTrustedWDart>('SetServiceAsTrustedW');
// szReserved : LPCWSTR optional -> Pointer<Utf16>
// szServiceName : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetServiceAsTrustedW(
szReserved: PWideChar; // LPCWSTR optional
szServiceName: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'loadperf.dll' name 'SetServiceAsTrustedW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetServiceAsTrustedW"
c_SetServiceAsTrustedW :: CWString -> CWString -> IO Word32
-- szReserved : LPCWSTR optional -> CWString
-- szServiceName : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setserviceastrustedw =
foreign "SetServiceAsTrustedW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* szReserved : LPCWSTR optional -> (ptr uint16_t) *)
(* szServiceName : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library loadperf (t "loadperf.dll"))
(cffi:use-foreign-library loadperf)
(cffi:defcfun ("SetServiceAsTrustedW" set-service-as-trusted-w :convention :stdcall) :uint32
(sz-reserved (:string :encoding :utf-16le)) ; LPCWSTR optional
(sz-service-name (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetServiceAsTrustedW = Win32::API::More->new('loadperf',
'DWORD SetServiceAsTrustedW(LPCWSTR szReserved, LPCWSTR szServiceName)');
# my $ret = $SetServiceAsTrustedW->Call($szReserved, $szServiceName);
# szReserved : LPCWSTR optional -> LPCWSTR
# szServiceName : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetServiceAsTrustedA (ANSI版) — サービスを信頼済みとして設定する。ANSI版。