ホーム › System.ApplicationInstallationAndServicing › MsiSetComponentStateA
MsiSetComponentStateA
関数コンポーネントのインストール状態を設定する(ANSI版)。
シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSetComponentStateA(
MSIHANDLE hInstall,
LPCSTR szComponent,
INSTALLSTATE iState
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに提供された、または MsiOpenPackage、MsiOpenPackageEx、MsiOpenProduct を通じて取得したインストールへのハンドルです。 | ||||||||
| szComponent | LPCSTR | in | コンポーネントの名前を指定します。 | ||||||||
| iState | INSTALLSTATE | in | 設定する状態を指定します。このパラメーターには、次のいずれかの値を指定できます。
|
戻り値の型: DWORD
公式ドキュメント
MsiSetComponentState 関数は、コンポーネントを要求された状態に設定します。(ANSI)
戻り値
MsiSetComponentState 関数は、次の値を返します。
解説(Remarks)
MsiSetComponentState 関数は、 Component テーブル内のレコードのアクション状態の変更を要求します。
詳細については、 プログラムからのデータベース関数の呼び出しを参照してください。
関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
メモ
msiquery.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiSetComponentState を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSetComponentStateA(
MSIHANDLE hInstall,
LPCSTR szComponent,
INSTALLSTATE iState
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiSetComponentStateA(
uint hInstall, // MSIHANDLE
[MarshalAs(UnmanagedType.LPStr)] string szComponent, // LPCSTR
int iState // INSTALLSTATE
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiSetComponentStateA(
hInstall As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPStr)> szComponent As String, ' LPCSTR
iState As Integer ' INSTALLSTATE
) As UInteger
End Function' hInstall : MSIHANDLE
' szComponent : LPCSTR
' iState : INSTALLSTATE
Declare PtrSafe Function MsiSetComponentStateA Lib "msi" ( _
ByVal hInstall As Long, _
ByVal szComponent As String, _
ByVal iState As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiSetComponentStateA = ctypes.windll.msi.MsiSetComponentStateA
MsiSetComponentStateA.restype = wintypes.DWORD
MsiSetComponentStateA.argtypes = [
wintypes.DWORD, # hInstall : MSIHANDLE
wintypes.LPCSTR, # szComponent : LPCSTR
ctypes.c_int, # iState : INSTALLSTATE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiSetComponentStateA = Fiddle::Function.new(
lib['MsiSetComponentStateA'],
[
-Fiddle::TYPE_INT, # hInstall : MSIHANDLE
Fiddle::TYPE_VOIDP, # szComponent : LPCSTR
Fiddle::TYPE_INT, # iState : INSTALLSTATE
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiSetComponentStateA(
hInstall: u32, // MSIHANDLE
szComponent: *const u8, // LPCSTR
iState: i32 // INSTALLSTATE
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiSetComponentStateA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szComponent, int iState);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSetComponentStateA' -Namespace Win32 -PassThru
# $api::MsiSetComponentStateA(hInstall, szComponent, iState)#uselib "msi.dll"
#func global MsiSetComponentStateA "MsiSetComponentStateA" sptr, sptr, sptr
; MsiSetComponentStateA hInstall, szComponent, iState ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szComponent : LPCSTR -> "sptr"
; iState : INSTALLSTATE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiSetComponentStateA "MsiSetComponentStateA" int, str, int
; res = MsiSetComponentStateA(hInstall, szComponent, iState)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCSTR -> "str"
; iState : INSTALLSTATE -> "int"; DWORD MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent, INSTALLSTATE iState)
#uselib "msi.dll"
#cfunc global MsiSetComponentStateA "MsiSetComponentStateA" int, str, int
; res = MsiSetComponentStateA(hInstall, szComponent, iState)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCSTR -> "str"
; iState : INSTALLSTATE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiSetComponentStateA = msi.NewProc("MsiSetComponentStateA")
)
// hInstall (MSIHANDLE), szComponent (LPCSTR), iState (INSTALLSTATE)
r1, _, err := procMsiSetComponentStateA.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szComponent))),
uintptr(iState),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiSetComponentStateA(
hInstall: DWORD; // MSIHANDLE
szComponent: PAnsiChar; // LPCSTR
iState: Integer // INSTALLSTATE
): DWORD; stdcall;
external 'msi.dll' name 'MsiSetComponentStateA';result := DllCall("msi\MsiSetComponentStateA"
, "UInt", hInstall ; MSIHANDLE
, "AStr", szComponent ; LPCSTR
, "Int", iState ; INSTALLSTATE
, "UInt") ; return: DWORD●MsiSetComponentStateA(hInstall, szComponent, iState) = DLL("msi.dll", "dword MsiSetComponentStateA(dword, char*, int)")
# 呼び出し: MsiSetComponentStateA(hInstall, szComponent, iState)
# hInstall : MSIHANDLE -> "dword"
# szComponent : LPCSTR -> "char*"
# iState : INSTALLSTATE -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiSetComponentStateA(
hInstall: u32, // MSIHANDLE
szComponent: [*c]const u8, // LPCSTR
iState: i32 // INSTALLSTATE
) callconv(std.os.windows.WINAPI) u32;proc MsiSetComponentStateA(
hInstall: uint32, # MSIHANDLE
szComponent: cstring, # LPCSTR
iState: int32 # INSTALLSTATE
): uint32 {.importc: "MsiSetComponentStateA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiSetComponentStateA(
uint hInstall, // MSIHANDLE
const(char)* szComponent, // LPCSTR
int iState // INSTALLSTATE
);ccall((:MsiSetComponentStateA, "msi.dll"), stdcall, UInt32,
(UInt32, Cstring, Int32),
hInstall, szComponent, iState)
# hInstall : MSIHANDLE -> UInt32
# szComponent : LPCSTR -> Cstring
# iState : INSTALLSTATE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSetComponentStateA(
uint32_t hInstall,
const char* szComponent,
int32_t iState);
]]
local msi = ffi.load("msi")
-- msi.MsiSetComponentStateA(hInstall, szComponent, iState)
-- hInstall : MSIHANDLE
-- szComponent : LPCSTR
-- iState : INSTALLSTATE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiSetComponentStateA = lib.func('__stdcall', 'MsiSetComponentStateA', 'uint32_t', ['uint32_t', 'str', 'int32_t']);
// MsiSetComponentStateA(hInstall, szComponent, iState)
// hInstall : MSIHANDLE -> 'uint32_t'
// szComponent : LPCSTR -> 'str'
// iState : INSTALLSTATE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiSetComponentStateA: { parameters: ["u32", "buffer", "i32"], result: "u32" },
});
// lib.symbols.MsiSetComponentStateA(hInstall, szComponent, iState)
// hInstall : MSIHANDLE -> "u32"
// szComponent : LPCSTR -> "buffer"
// iState : INSTALLSTATE -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSetComponentStateA(
uint32_t hInstall,
const char* szComponent,
int32_t iState);
C, "msi.dll");
// $ffi->MsiSetComponentStateA(hInstall, szComponent, iState);
// hInstall : MSIHANDLE
// szComponent : LPCSTR
// iState : INSTALLSTATE
// 構造体/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 Msi extends StdCallLibrary {
Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
int MsiSetComponentStateA(
int hInstall, // MSIHANDLE
String szComponent, // LPCSTR
int iState // INSTALLSTATE
);
}@[Link("msi")]
lib Libmsi
fun MsiSetComponentStateA = MsiSetComponentStateA(
hInstall : UInt32, # MSIHANDLE
szComponent : UInt8*, # LPCSTR
iState : Int32 # INSTALLSTATE
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiSetComponentStateANative = Uint32 Function(Uint32, Pointer<Utf8>, Int32);
typedef MsiSetComponentStateADart = int Function(int, Pointer<Utf8>, int);
final MsiSetComponentStateA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiSetComponentStateANative, MsiSetComponentStateADart>('MsiSetComponentStateA');
// hInstall : MSIHANDLE -> Uint32
// szComponent : LPCSTR -> Pointer<Utf8>
// iState : INSTALLSTATE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiSetComponentStateA(
hInstall: DWORD; // MSIHANDLE
szComponent: PAnsiChar; // LPCSTR
iState: Integer // INSTALLSTATE
): DWORD; stdcall;
external 'msi.dll' name 'MsiSetComponentStateA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiSetComponentStateA"
c_MsiSetComponentStateA :: Word32 -> CString -> Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szComponent : LPCSTR -> CString
-- iState : INSTALLSTATE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msisetcomponentstatea =
foreign "MsiSetComponentStateA"
(uint32_t @-> string @-> int32_t @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szComponent : LPCSTR -> string *)
(* iState : INSTALLSTATE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiSetComponentStateA" msi-set-component-state-a :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-component :string) ; LPCSTR
(i-state :int32)) ; INSTALLSTATE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiSetComponentStateA = Win32::API::More->new('msi',
'DWORD MsiSetComponentStateA(DWORD hInstall, LPCSTR szComponent, int iState)');
# my $ret = $MsiSetComponentStateA->Call($hInstall, $szComponent, $iState);
# hInstall : MSIHANDLE -> DWORD
# szComponent : LPCSTR -> LPCSTR
# iState : INSTALLSTATE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f MsiSetComponentStateW (Unicode版) — コンポーネントのインストール状態を設定する(Unicode版)。
使用する型