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

GetSharedServiceDirectory

関数
共有サービスのディレクトリパスを取得する。
DLLapi-ms-win-service-core-l1-1-5.dll呼出規約winapi

シグネチャ

// api-ms-win-service-core-l1-1-5.dll
#include <windows.h>

DWORD GetSharedServiceDirectory(
    SC_HANDLE ServiceHandle,
    SERVICE_SHARED_DIRECTORY_TYPE DirectoryType,
    LPWSTR PathBuffer,   // optional
    DWORD PathBufferLength,
    DWORD* RequiredBufferLength
);

パラメーター

名前方向
ServiceHandleSC_HANDLEin
DirectoryTypeSERVICE_SHARED_DIRECTORY_TYPEin
PathBufferLPWSTRoutoptional
PathBufferLengthDWORDin
RequiredBufferLengthDWORD*out

戻り値の型: DWORD

各言語での呼び出し定義

// api-ms-win-service-core-l1-1-5.dll
#include <windows.h>

DWORD GetSharedServiceDirectory(
    SC_HANDLE ServiceHandle,
    SERVICE_SHARED_DIRECTORY_TYPE DirectoryType,
    LPWSTR PathBuffer,   // optional
    DWORD PathBufferLength,
    DWORD* RequiredBufferLength
);
[DllImport("api-ms-win-service-core-l1-1-5.dll", ExactSpelling = true)]
static extern uint GetSharedServiceDirectory(
    IntPtr ServiceHandle,   // SC_HANDLE
    int DirectoryType,   // SERVICE_SHARED_DIRECTORY_TYPE
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathBuffer,   // LPWSTR optional, out
    uint PathBufferLength,   // DWORD
    out uint RequiredBufferLength   // DWORD* out
);
<DllImport("api-ms-win-service-core-l1-1-5.dll", ExactSpelling:=True)>
Public Shared Function GetSharedServiceDirectory(
    ServiceHandle As IntPtr,   ' SC_HANDLE
    DirectoryType As Integer,   ' SERVICE_SHARED_DIRECTORY_TYPE
    <MarshalAs(UnmanagedType.LPWStr)> PathBuffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    PathBufferLength As UInteger,   ' DWORD
    <Out> ByRef RequiredBufferLength As UInteger   ' DWORD* out
) As UInteger
End Function
' ServiceHandle : SC_HANDLE
' DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE
' PathBuffer : LPWSTR optional, out
' PathBufferLength : DWORD
' RequiredBufferLength : DWORD* out
Declare PtrSafe Function GetSharedServiceDirectory Lib "api-ms-win-service-core-l1-1-5" ( _
    ByVal ServiceHandle As LongPtr, _
    ByVal DirectoryType As Long, _
    ByVal PathBuffer As LongPtr, _
    ByVal PathBufferLength As Long, _
    ByRef RequiredBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSharedServiceDirectory = ctypes.windll.LoadLibrary("api-ms-win-service-core-l1-1-5.dll").GetSharedServiceDirectory
GetSharedServiceDirectory.restype = wintypes.DWORD
GetSharedServiceDirectory.argtypes = [
    wintypes.HANDLE,  # ServiceHandle : SC_HANDLE
    ctypes.c_int,  # DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE
    wintypes.LPWSTR,  # PathBuffer : LPWSTR optional, out
    wintypes.DWORD,  # PathBufferLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RequiredBufferLength : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-service-core-l1-1-5.dll')
GetSharedServiceDirectory = Fiddle::Function.new(
  lib['GetSharedServiceDirectory'],
  [
    Fiddle::TYPE_VOIDP,  # ServiceHandle : SC_HANDLE
    Fiddle::TYPE_INT,  # DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE
    Fiddle::TYPE_VOIDP,  # PathBuffer : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # PathBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredBufferLength : DWORD* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "api-ms-win-service-core-l1-1-5")]
extern "system" {
    fn GetSharedServiceDirectory(
        ServiceHandle: *mut core::ffi::c_void,  // SC_HANDLE
        DirectoryType: i32,  // SERVICE_SHARED_DIRECTORY_TYPE
        PathBuffer: *mut u16,  // LPWSTR optional, out
        PathBufferLength: u32,  // DWORD
        RequiredBufferLength: *mut u32  // DWORD* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-service-core-l1-1-5.dll")]
public static extern uint GetSharedServiceDirectory(IntPtr ServiceHandle, int DirectoryType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathBuffer, uint PathBufferLength, out uint RequiredBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-service-core-l1-1-5_GetSharedServiceDirectory' -Namespace Win32 -PassThru
# $api::GetSharedServiceDirectory(ServiceHandle, DirectoryType, PathBuffer, PathBufferLength, RequiredBufferLength)
#uselib "api-ms-win-service-core-l1-1-5.dll"
#func global GetSharedServiceDirectory "GetSharedServiceDirectory" sptr, sptr, sptr, sptr, sptr
; GetSharedServiceDirectory ServiceHandle, DirectoryType, varptr(PathBuffer), PathBufferLength, varptr(RequiredBufferLength)   ; 戻り値は stat
; ServiceHandle : SC_HANDLE -> "sptr"
; DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE -> "sptr"
; PathBuffer : LPWSTR optional, out -> "sptr"
; PathBufferLength : DWORD -> "sptr"
; RequiredBufferLength : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-service-core-l1-1-5.dll"
#cfunc global GetSharedServiceDirectory "GetSharedServiceDirectory" sptr, int, var, int, var
; res = GetSharedServiceDirectory(ServiceHandle, DirectoryType, PathBuffer, PathBufferLength, RequiredBufferLength)
; ServiceHandle : SC_HANDLE -> "sptr"
; DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE -> "int"
; PathBuffer : LPWSTR optional, out -> "var"
; PathBufferLength : DWORD -> "int"
; RequiredBufferLength : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetSharedServiceDirectory(SC_HANDLE ServiceHandle, SERVICE_SHARED_DIRECTORY_TYPE DirectoryType, LPWSTR PathBuffer, DWORD PathBufferLength, DWORD* RequiredBufferLength)
#uselib "api-ms-win-service-core-l1-1-5.dll"
#cfunc global GetSharedServiceDirectory "GetSharedServiceDirectory" intptr, int, var, int, var
; res = GetSharedServiceDirectory(ServiceHandle, DirectoryType, PathBuffer, PathBufferLength, RequiredBufferLength)
; ServiceHandle : SC_HANDLE -> "intptr"
; DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE -> "int"
; PathBuffer : LPWSTR optional, out -> "var"
; PathBufferLength : DWORD -> "int"
; RequiredBufferLength : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_service_core_l1_1_5 = windows.NewLazySystemDLL("api-ms-win-service-core-l1-1-5.dll")
	procGetSharedServiceDirectory = api_ms_win_service_core_l1_1_5.NewProc("GetSharedServiceDirectory")
)

// ServiceHandle (SC_HANDLE), DirectoryType (SERVICE_SHARED_DIRECTORY_TYPE), PathBuffer (LPWSTR optional, out), PathBufferLength (DWORD), RequiredBufferLength (DWORD* out)
r1, _, err := procGetSharedServiceDirectory.Call(
	uintptr(ServiceHandle),
	uintptr(DirectoryType),
	uintptr(PathBuffer),
	uintptr(PathBufferLength),
	uintptr(RequiredBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetSharedServiceDirectory(
  ServiceHandle: THandle;   // SC_HANDLE
  DirectoryType: Integer;   // SERVICE_SHARED_DIRECTORY_TYPE
  PathBuffer: PWideChar;   // LPWSTR optional, out
  PathBufferLength: DWORD;   // DWORD
  RequiredBufferLength: Pointer   // DWORD* out
): DWORD; stdcall;
  external 'api-ms-win-service-core-l1-1-5.dll' name 'GetSharedServiceDirectory';
result := DllCall("api-ms-win-service-core-l1-1-5\GetSharedServiceDirectory"
    , "Ptr", ServiceHandle   ; SC_HANDLE
    , "Int", DirectoryType   ; SERVICE_SHARED_DIRECTORY_TYPE
    , "Ptr", PathBuffer   ; LPWSTR optional, out
    , "UInt", PathBufferLength   ; DWORD
    , "Ptr", RequiredBufferLength   ; DWORD* out
    , "UInt")   ; return: DWORD
●GetSharedServiceDirectory(ServiceHandle, DirectoryType, PathBuffer, PathBufferLength, RequiredBufferLength) = DLL("api-ms-win-service-core-l1-1-5.dll", "dword GetSharedServiceDirectory(void*, int, char*, dword, void*)")
# 呼び出し: GetSharedServiceDirectory(ServiceHandle, DirectoryType, PathBuffer, PathBufferLength, RequiredBufferLength)
# ServiceHandle : SC_HANDLE -> "void*"
# DirectoryType : SERVICE_SHARED_DIRECTORY_TYPE -> "int"
# PathBuffer : LPWSTR optional, out -> "char*"
# PathBufferLength : DWORD -> "dword"
# RequiredBufferLength : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。