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

MsiUseFeatureW

関数
機能の使用を記録し利用可能か返す(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

INSTALLSTATE MsiUseFeatureW(
    LPCWSTR szProduct,
    LPCWSTR szFeature
);

パラメーター

名前方向
szProductLPCWSTRin
szFeatureLPCWSTRin

戻り値の型: INSTALLSTATE

各言語での呼び出し定義

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

INSTALLSTATE MsiUseFeatureW(
    LPCWSTR szProduct,
    LPCWSTR szFeature
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiUseFeatureW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProduct,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szFeature   // LPCWSTR
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiUseFeatureW(
    <MarshalAs(UnmanagedType.LPWStr)> szProduct As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szFeature As String   ' LPCWSTR
) As Integer
End Function
' szProduct : LPCWSTR
' szFeature : LPCWSTR
Declare PtrSafe Function MsiUseFeatureW Lib "msi" ( _
    ByVal szProduct As LongPtr, _
    ByVal szFeature As LongPtr) 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

MsiUseFeatureW = ctypes.windll.msi.MsiUseFeatureW
MsiUseFeatureW.restype = ctypes.c_int
MsiUseFeatureW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    wintypes.LPCWSTR,  # szFeature : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiUseFeatureW = msi.NewProc("MsiUseFeatureW")
)

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