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

QueryServiceConfigW

関数
サービスの構成情報を取得する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL QueryServiceConfigW(
    SC_HANDLE hService,
    QUERY_SERVICE_CONFIGW* lpServiceConfig,   // optional
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded
);

パラメーター

名前方向
hServiceSC_HANDLEin
lpServiceConfigQUERY_SERVICE_CONFIGW*outoptional
cbBufSizeDWORDin
pcbBytesNeededDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL QueryServiceConfigW(
    SC_HANDLE hService,
    QUERY_SERVICE_CONFIGW* lpServiceConfig,   // optional
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool QueryServiceConfigW(
    IntPtr hService,   // SC_HANDLE
    IntPtr lpServiceConfig,   // QUERY_SERVICE_CONFIGW* optional, out
    uint cbBufSize,   // DWORD
    out uint pcbBytesNeeded   // DWORD* out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function QueryServiceConfigW(
    hService As IntPtr,   ' SC_HANDLE
    lpServiceConfig As IntPtr,   ' QUERY_SERVICE_CONFIGW* optional, out
    cbBufSize As UInteger,   ' DWORD
    <Out> ByRef pcbBytesNeeded As UInteger   ' DWORD* out
) As Boolean
End Function
' hService : SC_HANDLE
' lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out
' cbBufSize : DWORD
' pcbBytesNeeded : DWORD* out
Declare PtrSafe Function QueryServiceConfigW Lib "advapi32" ( _
    ByVal hService As LongPtr, _
    ByVal lpServiceConfig As LongPtr, _
    ByVal cbBufSize As Long, _
    ByRef pcbBytesNeeded 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

QueryServiceConfigW = ctypes.windll.advapi32.QueryServiceConfigW
QueryServiceConfigW.restype = wintypes.BOOL
QueryServiceConfigW.argtypes = [
    wintypes.HANDLE,  # hService : SC_HANDLE
    ctypes.c_void_p,  # lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out
    wintypes.DWORD,  # cbBufSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pcbBytesNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
QueryServiceConfigW = Fiddle::Function.new(
  lib['QueryServiceConfigW'],
  [
    Fiddle::TYPE_VOIDP,  # hService : SC_HANDLE
    Fiddle::TYPE_VOIDP,  # lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out
    -Fiddle::TYPE_INT,  # cbBufSize : DWORD
    Fiddle::TYPE_VOIDP,  # pcbBytesNeeded : DWORD* out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn QueryServiceConfigW(
        hService: *mut core::ffi::c_void,  // SC_HANDLE
        lpServiceConfig: *mut QUERY_SERVICE_CONFIGW,  // QUERY_SERVICE_CONFIGW* optional, out
        cbBufSize: u32,  // DWORD
        pcbBytesNeeded: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool QueryServiceConfigW(IntPtr hService, IntPtr lpServiceConfig, uint cbBufSize, out uint pcbBytesNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_QueryServiceConfigW' -Namespace Win32 -PassThru
# $api::QueryServiceConfigW(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#func global QueryServiceConfigW "QueryServiceConfigW" wptr, wptr, wptr, wptr
; QueryServiceConfigW hService, varptr(lpServiceConfig), cbBufSize, varptr(pcbBytesNeeded)   ; 戻り値は stat
; hService : SC_HANDLE -> "wptr"
; lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out -> "wptr"
; cbBufSize : DWORD -> "wptr"
; pcbBytesNeeded : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global QueryServiceConfigW "QueryServiceConfigW" sptr, var, int, var
; res = QueryServiceConfigW(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded)
; hService : SC_HANDLE -> "sptr"
; lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out -> "var"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryServiceConfigW(SC_HANDLE hService, QUERY_SERVICE_CONFIGW* lpServiceConfig, DWORD cbBufSize, DWORD* pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#cfunc global QueryServiceConfigW "QueryServiceConfigW" intptr, var, int, var
; res = QueryServiceConfigW(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded)
; hService : SC_HANDLE -> "intptr"
; lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out -> "var"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procQueryServiceConfigW = advapi32.NewProc("QueryServiceConfigW")
)

// hService (SC_HANDLE), lpServiceConfig (QUERY_SERVICE_CONFIGW* optional, out), cbBufSize (DWORD), pcbBytesNeeded (DWORD* out)
r1, _, err := procQueryServiceConfigW.Call(
	uintptr(hService),
	uintptr(lpServiceConfig),
	uintptr(cbBufSize),
	uintptr(pcbBytesNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function QueryServiceConfigW(
  hService: THandle;   // SC_HANDLE
  lpServiceConfig: Pointer;   // QUERY_SERVICE_CONFIGW* optional, out
  cbBufSize: DWORD;   // DWORD
  pcbBytesNeeded: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'QueryServiceConfigW';
result := DllCall("ADVAPI32\QueryServiceConfigW"
    , "Ptr", hService   ; SC_HANDLE
    , "Ptr", lpServiceConfig   ; QUERY_SERVICE_CONFIGW* optional, out
    , "UInt", cbBufSize   ; DWORD
    , "Ptr", pcbBytesNeeded   ; DWORD* out
    , "Int")   ; return: BOOL
●QueryServiceConfigW(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded) = DLL("ADVAPI32.dll", "bool QueryServiceConfigW(void*, void*, dword, void*)")
# 呼び出し: QueryServiceConfigW(hService, lpServiceConfig, cbBufSize, pcbBytesNeeded)
# hService : SC_HANDLE -> "void*"
# lpServiceConfig : QUERY_SERVICE_CONFIGW* optional, out -> "void*"
# cbBufSize : DWORD -> "dword"
# pcbBytesNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。