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

MsiUseFeatureExW

関数
モード指定で機能の使用を記録し状態を返す(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (Unicode / -W)
#include <windows.h>

INSTALLSTATE MsiUseFeatureExW(
    LPCWSTR szProduct,
    LPCWSTR szFeature,
    DWORD dwInstallMode,
    DWORD dwReserved   // optional
);

パラメーター

名前方向
szProductLPCWSTRin
szFeatureLPCWSTRin
dwInstallModeDWORDin
dwReservedDWORDoptional

戻り値の型: INSTALLSTATE

各言語での呼び出し定義

// msi.dll  (Unicode / -W)
#include <windows.h>

INSTALLSTATE MsiUseFeatureExW(
    LPCWSTR szProduct,
    LPCWSTR szFeature,
    DWORD dwInstallMode,
    DWORD dwReserved   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiUseFeatureExW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProduct,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szFeature,   // LPCWSTR
    uint dwInstallMode,   // DWORD
    uint dwReserved   // DWORD optional
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiUseFeatureExW(
    <MarshalAs(UnmanagedType.LPWStr)> szProduct As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szFeature As String,   ' LPCWSTR
    dwInstallMode As UInteger,   ' DWORD
    dwReserved As UInteger   ' DWORD optional
) As Integer
End Function
' szProduct : LPCWSTR
' szFeature : LPCWSTR
' dwInstallMode : DWORD
' dwReserved : DWORD optional
Declare PtrSafe Function MsiUseFeatureExW Lib "msi" ( _
    ByVal szProduct As LongPtr, _
    ByVal szFeature As LongPtr, _
    ByVal dwInstallMode As Long, _
    ByVal dwReserved As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiUseFeatureExW = ctypes.windll.msi.MsiUseFeatureExW
MsiUseFeatureExW.restype = ctypes.c_int
MsiUseFeatureExW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    wintypes.LPCWSTR,  # szFeature : LPCWSTR
    wintypes.DWORD,  # dwInstallMode : DWORD
    wintypes.DWORD,  # dwReserved : DWORD optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiUseFeatureExW = Fiddle::Function.new(
  lib['MsiUseFeatureExW'],
  [
    Fiddle::TYPE_VOIDP,  # szProduct : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szFeature : LPCWSTR
    -Fiddle::TYPE_INT,  # dwInstallMode : DWORD
    -Fiddle::TYPE_INT,  # dwReserved : DWORD optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiUseFeatureExW(
        szProduct: *const u16,  // LPCWSTR
        szFeature: *const u16,  // LPCWSTR
        dwInstallMode: u32,  // DWORD
        dwReserved: u32  // DWORD optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiUseFeatureExW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] string szFeature, uint dwInstallMode, uint dwReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiUseFeatureExW' -Namespace Win32 -PassThru
# $api::MsiUseFeatureExW(szProduct, szFeature, dwInstallMode, dwReserved)
#uselib "msi.dll"
#func global MsiUseFeatureExW "MsiUseFeatureExW" wptr, wptr, wptr, wptr
; MsiUseFeatureExW szProduct, szFeature, dwInstallMode, dwReserved   ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; szFeature : LPCWSTR -> "wptr"
; dwInstallMode : DWORD -> "wptr"
; dwReserved : DWORD optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiUseFeatureExW "MsiUseFeatureExW" wstr, wstr, int, int
; res = MsiUseFeatureExW(szProduct, szFeature, dwInstallMode, dwReserved)
; szProduct : LPCWSTR -> "wstr"
; szFeature : LPCWSTR -> "wstr"
; dwInstallMode : DWORD -> "int"
; dwReserved : DWORD optional -> "int"
; INSTALLSTATE MsiUseFeatureExW(LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwInstallMode, DWORD dwReserved)
#uselib "msi.dll"
#cfunc global MsiUseFeatureExW "MsiUseFeatureExW" wstr, wstr, int, int
; res = MsiUseFeatureExW(szProduct, szFeature, dwInstallMode, dwReserved)
; szProduct : LPCWSTR -> "wstr"
; szFeature : LPCWSTR -> "wstr"
; dwInstallMode : DWORD -> "int"
; dwReserved : DWORD optional -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiUseFeatureExW = msi.NewProc("MsiUseFeatureExW")
)

// szProduct (LPCWSTR), szFeature (LPCWSTR), dwInstallMode (DWORD), dwReserved (DWORD optional)
r1, _, err := procMsiUseFeatureExW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProduct))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFeature))),
	uintptr(dwInstallMode),
	uintptr(dwReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INSTALLSTATE
function MsiUseFeatureExW(
  szProduct: PWideChar;   // LPCWSTR
  szFeature: PWideChar;   // LPCWSTR
  dwInstallMode: DWORD;   // DWORD
  dwReserved: DWORD   // DWORD optional
): Integer; stdcall;
  external 'msi.dll' name 'MsiUseFeatureExW';
result := DllCall("msi\MsiUseFeatureExW"
    , "WStr", szProduct   ; LPCWSTR
    , "WStr", szFeature   ; LPCWSTR
    , "UInt", dwInstallMode   ; DWORD
    , "UInt", dwReserved   ; DWORD optional
    , "Int")   ; return: INSTALLSTATE
●MsiUseFeatureExW(szProduct, szFeature, dwInstallMode, dwReserved) = DLL("msi.dll", "int MsiUseFeatureExW(char*, char*, dword, dword)")
# 呼び出し: MsiUseFeatureExW(szProduct, szFeature, dwInstallMode, dwReserved)
# szProduct : LPCWSTR -> "char*"
# szFeature : LPCWSTR -> "char*"
# dwInstallMode : DWORD -> "dword"
# dwReserved : DWORD optional -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。