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

MsiSetComponentStateA

関数
コンポーネントのインストール状態を設定する(ANSI版)。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiSetComponentStateA(
    MSIHANDLE hInstall,
    LPCSTR szComponent,
    INSTALLSTATE iState
);

パラメーター

名前方向
hInstallMSIHANDLEin
szComponentLPCSTRin
iStateINSTALLSTATEin

戻り値の型: DWORD

各言語での呼び出し定義

// 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   // DWORD
function 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)。