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

QueryServiceLockStatusW

関数
SCMデータベースのロック状態を取得する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL QueryServiceLockStatusW(
    SC_HANDLE hSCManager,
    QUERY_SERVICE_LOCK_STATUSW* lpLockStatus,   // optional
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded
);

パラメーター

名前方向
hSCManagerSC_HANDLEin
lpLockStatusQUERY_SERVICE_LOCK_STATUSW*outoptional
cbBufSizeDWORDin
pcbBytesNeededDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

QueryServiceLockStatusW = ctypes.windll.advapi32.QueryServiceLockStatusW
QueryServiceLockStatusW.restype = wintypes.BOOL
QueryServiceLockStatusW.argtypes = [
    wintypes.HANDLE,  # hSCManager : SC_HANDLE
    ctypes.c_void_p,  # lpLockStatus : QUERY_SERVICE_LOCK_STATUSW* 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')
QueryServiceLockStatusW = Fiddle::Function.new(
  lib['QueryServiceLockStatusW'],
  [
    Fiddle::TYPE_VOIDP,  # hSCManager : SC_HANDLE
    Fiddle::TYPE_VOIDP,  # lpLockStatus : QUERY_SERVICE_LOCK_STATUSW* 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 QueryServiceLockStatusW(
        hSCManager: *mut core::ffi::c_void,  // SC_HANDLE
        lpLockStatus: *mut QUERY_SERVICE_LOCK_STATUSW,  // QUERY_SERVICE_LOCK_STATUSW* 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 QueryServiceLockStatusW(IntPtr hSCManager, IntPtr lpLockStatus, uint cbBufSize, out uint pcbBytesNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_QueryServiceLockStatusW' -Namespace Win32 -PassThru
# $api::QueryServiceLockStatusW(hSCManager, lpLockStatus, cbBufSize, pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#func global QueryServiceLockStatusW "QueryServiceLockStatusW" wptr, wptr, wptr, wptr
; QueryServiceLockStatusW hSCManager, varptr(lpLockStatus), cbBufSize, varptr(pcbBytesNeeded)   ; 戻り値は stat
; hSCManager : SC_HANDLE -> "wptr"
; lpLockStatus : QUERY_SERVICE_LOCK_STATUSW* optional, out -> "wptr"
; cbBufSize : DWORD -> "wptr"
; pcbBytesNeeded : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global QueryServiceLockStatusW "QueryServiceLockStatusW" sptr, var, int, var
; res = QueryServiceLockStatusW(hSCManager, lpLockStatus, cbBufSize, pcbBytesNeeded)
; hSCManager : SC_HANDLE -> "sptr"
; lpLockStatus : QUERY_SERVICE_LOCK_STATUSW* optional, out -> "var"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryServiceLockStatusW(SC_HANDLE hSCManager, QUERY_SERVICE_LOCK_STATUSW* lpLockStatus, DWORD cbBufSize, DWORD* pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#cfunc global QueryServiceLockStatusW "QueryServiceLockStatusW" intptr, var, int, var
; res = QueryServiceLockStatusW(hSCManager, lpLockStatus, cbBufSize, pcbBytesNeeded)
; hSCManager : SC_HANDLE -> "intptr"
; lpLockStatus : QUERY_SERVICE_LOCK_STATUSW* 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")
	procQueryServiceLockStatusW = advapi32.NewProc("QueryServiceLockStatusW")
)

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