ホーム › Devices.DeviceAndDriverInstallation › SetupInstallServicesFromInfSectionA
SetupInstallServicesFromInfSectionA
関数INFセクションの指定に従いサービスをインストール設定する。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupInstallServicesFromInfSectionA(
void* InfHandle,
LPCSTR SectionName,
SPSVCINST_FLAGS Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfHandle | void* | in | サービス情報を記述したINFファイルのハンドル。 |
| SectionName | LPCSTR | in | サービスインストールを記述したINFのセクション名(ANSI)。 |
| Flags | SPSVCINST_FLAGS | in | SPSVCINST_*系のサービスインストール動作フラグ。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "setupapi" fn SetupInstallServicesFromInfSectionA(
InfHandle: ?*anyopaque, // void*
SectionName: [*c]const u8, // LPCSTR
Flags: u32 // SPSVCINST_FLAGS
) callconv(std.os.windows.WINAPI) i32;proc SetupInstallServicesFromInfSectionA(
InfHandle: pointer, # void*
SectionName: cstring, # LPCSTR
Flags: uint32 # SPSVCINST_FLAGS
): int32 {.importc: "SetupInstallServicesFromInfSectionA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupInstallServicesFromInfSectionA(
void* InfHandle, // void*
const(char)* SectionName, // LPCSTR
uint Flags // SPSVCINST_FLAGS
);ccall((:SetupInstallServicesFromInfSectionA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cstring, UInt32),
InfHandle, SectionName, Flags)
# InfHandle : void* -> Ptr{Cvoid}
# SectionName : LPCSTR -> Cstring
# Flags : SPSVCINST_FLAGS -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupInstallServicesFromInfSectionA(
void* InfHandle,
const char* SectionName,
uint32_t Flags);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
-- InfHandle : void*
-- SectionName : LPCSTR
-- Flags : SPSVCINST_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupInstallServicesFromInfSectionA = lib.func('__stdcall', 'SetupInstallServicesFromInfSectionA', 'int32_t', ['void *', 'str', 'uint32_t']);
// SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
// InfHandle : void* -> 'void *'
// SectionName : LPCSTR -> 'str'
// Flags : SPSVCINST_FLAGS -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupInstallServicesFromInfSectionA: { parameters: ["pointer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags)
// InfHandle : void* -> "pointer"
// SectionName : LPCSTR -> "buffer"
// Flags : SPSVCINST_FLAGS -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupInstallServicesFromInfSectionA(
void* InfHandle,
const char* SectionName,
uint32_t Flags);
C, "SETUPAPI.dll");
// $ffi->SetupInstallServicesFromInfSectionA(InfHandle, SectionName, Flags);
// InfHandle : void*
// SectionName : LPCSTR
// Flags : SPSVCINST_FLAGS
// 構造体/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.ASCII_OPTIONS);
boolean SetupInstallServicesFromInfSectionA(
Pointer InfHandle, // void*
String SectionName, // LPCSTR
int Flags // SPSVCINST_FLAGS
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupInstallServicesFromInfSectionA = SetupInstallServicesFromInfSectionA(
InfHandle : Void*, # void*
SectionName : UInt8*, # LPCSTR
Flags : UInt32 # SPSVCINST_FLAGS
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupInstallServicesFromInfSectionANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32);
typedef SetupInstallServicesFromInfSectionADart = int Function(Pointer<Void>, Pointer<Utf8>, int);
final SetupInstallServicesFromInfSectionA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupInstallServicesFromInfSectionANative, SetupInstallServicesFromInfSectionADart>('SetupInstallServicesFromInfSectionA');
// InfHandle : void* -> Pointer<Void>
// SectionName : LPCSTR -> Pointer<Utf8>
// Flags : SPSVCINST_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupInstallServicesFromInfSectionA(
InfHandle: Pointer; // void*
SectionName: PAnsiChar; // LPCSTR
Flags: DWORD // SPSVCINST_FLAGS
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupInstallServicesFromInfSectionA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupInstallServicesFromInfSectionA"
c_SetupInstallServicesFromInfSectionA :: Ptr () -> CString -> Word32 -> IO CInt
-- InfHandle : void* -> Ptr ()
-- SectionName : LPCSTR -> CString
-- Flags : SPSVCINST_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupinstallservicesfrominfsectiona =
foreign "SetupInstallServicesFromInfSectionA"
((ptr void) @-> string @-> uint32_t @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* SectionName : LPCSTR -> string *)
(* Flags : SPSVCINST_FLAGS -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupInstallServicesFromInfSectionA" setup-install-services-from-inf-section-a :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(section-name :string) ; LPCSTR
(flags :uint32)) ; SPSVCINST_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupInstallServicesFromInfSectionA = Win32::API::More->new('SETUPAPI',
'BOOL SetupInstallServicesFromInfSectionA(LPVOID InfHandle, LPCSTR SectionName, DWORD Flags)');
# my $ret = $SetupInstallServicesFromInfSectionA->Call($InfHandle, $SectionName, $Flags);
# InfHandle : void* -> LPVOID
# SectionName : LPCSTR -> LPCSTR
# Flags : SPSVCINST_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupInstallServicesFromInfSectionW (Unicode版) — INFセクションの指定に従いサービスをインストール設定する。
類似 API
- f SetupInstallServicesFromInfSectionExA — デバイス情報を指定しINFセクションのサービスをインストールする。
使用する型