Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupInstallServicesFromInfSectionA

SetupInstallServicesFromInfSectionA

関数
INFセクションの指定に従いサービスをインストール設定する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupInstallServicesFromInfSectionA(
    void* InfHandle,
    LPCSTR SectionName,
    SPSVCINST_FLAGS Flags
);

パラメーター

名前方向
InfHandlevoid*in
SectionNameLPCSTRin
FlagsSPSVCINST_FLAGSin

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupInstallServicesFromInfSectionA(
    void* InfHandle,
    LPCSTR SectionName,
    SPSVCINST_FLAGS Flags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallServicesFromInfSectionA(
    IntPtr InfHandle,   // void*
    [MarshalAs(UnmanagedType.LPStr)] string SectionName,   // LPCSTR
    uint Flags   // SPSVCINST_FLAGS
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallServicesFromInfSectionA(
    InfHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> SectionName As String,   ' LPCSTR
    Flags As UInteger   ' SPSVCINST_FLAGS
) As Boolean
End Function
' InfHandle : void*
' SectionName : LPCSTR
' Flags : SPSVCINST_FLAGS
Declare PtrSafe Function SetupInstallServicesFromInfSectionA Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal SectionName As String, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupInstallServicesFromInfSectionA = ctypes.windll.setupapi.SetupInstallServicesFromInfSectionA
SetupInstallServicesFromInfSectionA.restype = wintypes.BOOL
SetupInstallServicesFromInfSectionA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCSTR,  # SectionName : LPCSTR
    wintypes.DWORD,  # Flags : SPSVCINST_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupInstallServicesFromInfSectionA = Fiddle::Function.new(
  lib['SetupInstallServicesFromInfSectionA'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    Fiddle::TYPE_VOIDP,  # SectionName : LPCSTR
    -Fiddle::TYPE_INT,  # Flags : SPSVCINST_FLAGS
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupInstallServicesFromInfSectionA(
        InfHandle: *mut (),  // void*
        SectionName: *const u8,  // LPCSTR
        Flags: u32  // SPSVCINST_FLAGS
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupInstallServicesFromInfSectionA(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPStr)] string SectionName, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallServicesFromInfSectionA' -Namespace Win32 -PassThru
# $api::SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
#uselib "SETUPAPI.dll"
#func global SetupInstallServicesFromInfSectionA "SetupInstallServicesFromInfSectionA" sptr, sptr, sptr
; SetupInstallServicesFromInfSectionA InfHandle, SectionName, Flags   ; 戻り値は stat
; InfHandle : void* -> "sptr"
; SectionName : LPCSTR -> "sptr"
; Flags : SPSVCINST_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallServicesFromInfSectionA "SetupInstallServicesFromInfSectionA" sptr, str, int
; res = SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
; InfHandle : void* -> "sptr"
; SectionName : LPCSTR -> "str"
; Flags : SPSVCINST_FLAGS -> "int"
; BOOL SetupInstallServicesFromInfSectionA(void* InfHandle, LPCSTR SectionName, SPSVCINST_FLAGS Flags)
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallServicesFromInfSectionA "SetupInstallServicesFromInfSectionA" intptr, str, int
; res = SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
; InfHandle : void* -> "intptr"
; SectionName : LPCSTR -> "str"
; Flags : SPSVCINST_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupInstallServicesFromInfSectionA = setupapi.NewProc("SetupInstallServicesFromInfSectionA")
)

// InfHandle (void*), SectionName (LPCSTR), Flags (SPSVCINST_FLAGS)
r1, _, err := procSetupInstallServicesFromInfSectionA.Call(
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SectionName))),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupInstallServicesFromInfSectionA(
  InfHandle: Pointer;   // void*
  SectionName: PAnsiChar;   // LPCSTR
  Flags: DWORD   // SPSVCINST_FLAGS
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallServicesFromInfSectionA';
result := DllCall("SETUPAPI\SetupInstallServicesFromInfSectionA"
    , "Ptr", InfHandle   ; void*
    , "AStr", SectionName   ; LPCSTR
    , "UInt", Flags   ; SPSVCINST_FLAGS
    , "Int")   ; return: BOOL
●SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags) = DLL("SETUPAPI.dll", "bool SetupInstallServicesFromInfSectionA(void*, char*, dword)")
# 呼び出し: SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
# InfHandle : void* -> "void*"
# SectionName : LPCSTR -> "char*"
# Flags : SPSVCINST_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。