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

MsiGetFeatureUsageW

関数
機能の使用回数と最終使用日を取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetFeatureUsageW(
    LPCWSTR szProduct,
    LPCWSTR szFeature,
    DWORD* pdwUseCount,   // optional
    WORD* pwDateUsed   // optional
);

パラメーター

名前方向説明
szProductLPCWSTRin機能を含む製品の製品コードを指定します。
szFeatureLPCWSTRinメトリックを返す対象の機能の機能コードを指定します。
pdwUseCountDWORD*outoptional機能が使用された回数を示します。
pwDateUsedWORD*outoptional

機能が最後に使用された日付を指定します。日付は、次の表に示す MS-DOS 日付形式です。

ビット 意味
0 – 4
日 (1~31)
5 – 8
月 (1 = 1月、2 = 2月、以下同様)
9 – 15
1980 年からの年のオフセット (実際の年を得るには 1980 を加算)

戻り値の型: DWORD

公式ドキュメント

MsiGetFeatureUsage 関数は、製品の機能の使用状況メトリックを返します。(Unicode)

戻り値

MsiGetFeatureUsage 関数は、次の値を返します。

意味
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INSTALL_FAILURE
使用状況情報が利用できないか、製品または機能が無効です。
ERROR_SUCCESS
関数が正常に完了しました。

解説(Remarks)

メモ

msi.h ヘッダーは、MsiGetFeatureUsage を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が発生する可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD MsiGetFeatureUsageW(
    LPCWSTR szProduct,
    LPCWSTR szFeature,
    DWORD* pdwUseCount,   // optional
    WORD* pwDateUsed   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetFeatureUsageW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProduct,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szFeature,   // LPCWSTR
    IntPtr pdwUseCount,   // DWORD* optional, out
    IntPtr pwDateUsed   // WORD* optional, out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetFeatureUsageW(
    <MarshalAs(UnmanagedType.LPWStr)> szProduct As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szFeature As String,   ' LPCWSTR
    pdwUseCount As IntPtr,   ' DWORD* optional, out
    pwDateUsed As IntPtr   ' WORD* optional, out
) As UInteger
End Function
' szProduct : LPCWSTR
' szFeature : LPCWSTR
' pdwUseCount : DWORD* optional, out
' pwDateUsed : WORD* optional, out
Declare PtrSafe Function MsiGetFeatureUsageW Lib "msi" ( _
    ByVal szProduct As LongPtr, _
    ByVal szFeature As LongPtr, _
    ByVal pdwUseCount As LongPtr, _
    ByVal pwDateUsed 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

MsiGetFeatureUsageW = ctypes.windll.msi.MsiGetFeatureUsageW
MsiGetFeatureUsageW.restype = wintypes.DWORD
MsiGetFeatureUsageW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    wintypes.LPCWSTR,  # szFeature : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pdwUseCount : DWORD* optional, out
    ctypes.POINTER(ctypes.c_ushort),  # pwDateUsed : WORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetFeatureUsageW = Fiddle::Function.new(
  lib['MsiGetFeatureUsageW'],
  [
    Fiddle::TYPE_VOIDP,  # szProduct : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szFeature : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pdwUseCount : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # pwDateUsed : WORD* optional, out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetFeatureUsageW(
        szProduct: *const u16,  // LPCWSTR
        szFeature: *const u16,  // LPCWSTR
        pdwUseCount: *mut u32,  // DWORD* optional, out
        pwDateUsed: *mut u16  // WORD* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetFeatureUsageW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] string szFeature, IntPtr pdwUseCount, IntPtr pwDateUsed);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFeatureUsageW' -Namespace Win32 -PassThru
# $api::MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
#uselib "msi.dll"
#func global MsiGetFeatureUsageW "MsiGetFeatureUsageW" wptr, wptr, wptr, wptr
; MsiGetFeatureUsageW szProduct, szFeature, varptr(pdwUseCount), varptr(pwDateUsed)   ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; szFeature : LPCWSTR -> "wptr"
; pdwUseCount : DWORD* optional, out -> "wptr"
; pwDateUsed : WORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetFeatureUsageW "MsiGetFeatureUsageW" wstr, wstr, var, var
; res = MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
; szProduct : LPCWSTR -> "wstr"
; szFeature : LPCWSTR -> "wstr"
; pdwUseCount : DWORD* optional, out -> "var"
; pwDateUsed : WORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetFeatureUsageW(LPCWSTR szProduct, LPCWSTR szFeature, DWORD* pdwUseCount, WORD* pwDateUsed)
#uselib "msi.dll"
#cfunc global MsiGetFeatureUsageW "MsiGetFeatureUsageW" wstr, wstr, var, var
; res = MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
; szProduct : LPCWSTR -> "wstr"
; szFeature : LPCWSTR -> "wstr"
; pdwUseCount : DWORD* optional, out -> "var"
; pwDateUsed : WORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetFeatureUsageW = msi.NewProc("MsiGetFeatureUsageW")
)

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

extern "msi" fn MsiGetFeatureUsageW(
    szProduct: [*c]const u16, // LPCWSTR
    szFeature: [*c]const u16, // LPCWSTR
    pdwUseCount: [*c]u32, // DWORD* optional, out
    pwDateUsed: [*c]u16 // WORD* optional, out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiGetFeatureUsageW(
    szProduct: WideCString,  # LPCWSTR
    szFeature: WideCString,  # LPCWSTR
    pdwUseCount: ptr uint32,  # DWORD* optional, out
    pwDateUsed: ptr uint16  # WORD* optional, out
): uint32 {.importc: "MsiGetFeatureUsageW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiGetFeatureUsageW(
    const(wchar)* szProduct,   // LPCWSTR
    const(wchar)* szFeature,   // LPCWSTR
    uint* pdwUseCount,   // DWORD* optional, out
    ushort* pwDateUsed   // WORD* optional, out
);
ccall((:MsiGetFeatureUsageW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Ptr{UInt32}, Ptr{UInt16}),
      szProduct, szFeature, pdwUseCount, pwDateUsed)
# szProduct : LPCWSTR -> Cwstring
# szFeature : LPCWSTR -> Cwstring
# pdwUseCount : DWORD* optional, out -> Ptr{UInt32}
# pwDateUsed : WORD* optional, out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetFeatureUsageW(
    const uint16_t* szProduct,
    const uint16_t* szFeature,
    uint32_t* pdwUseCount,
    uint16_t* pwDateUsed);
]]
local msi = ffi.load("msi")
-- msi.MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
-- szProduct : LPCWSTR
-- szFeature : LPCWSTR
-- pdwUseCount : DWORD* optional, out
-- pwDateUsed : WORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetFeatureUsageW = lib.func('__stdcall', 'MsiGetFeatureUsageW', 'uint32_t', ['str16', 'str16', 'uint32_t *', 'uint16_t *']);
// MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
// szProduct : LPCWSTR -> 'str16'
// szFeature : LPCWSTR -> 'str16'
// pdwUseCount : DWORD* optional, out -> 'uint32_t *'
// pwDateUsed : WORD* optional, out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiGetFeatureUsageW: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed)
// szProduct : LPCWSTR -> "buffer"
// szFeature : LPCWSTR -> "buffer"
// pdwUseCount : DWORD* optional, out -> "pointer"
// pwDateUsed : WORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetFeatureUsageW(
    const uint16_t* szProduct,
    const uint16_t* szFeature,
    uint32_t* pdwUseCount,
    uint16_t* pwDateUsed);
C, "msi.dll");
// $ffi->MsiGetFeatureUsageW(szProduct, szFeature, pdwUseCount, pwDateUsed);
// szProduct : LPCWSTR
// szFeature : LPCWSTR
// pdwUseCount : DWORD* optional, out
// pwDateUsed : WORD* optional, out
// 構造体/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.UNICODE_OPTIONS);
    int MsiGetFeatureUsageW(
        WString szProduct,   // LPCWSTR
        WString szFeature,   // LPCWSTR
        IntByReference pdwUseCount,   // DWORD* optional, out
        ShortByReference pwDateUsed   // WORD* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiGetFeatureUsageW = MsiGetFeatureUsageW(
    szProduct : UInt16*,   # LPCWSTR
    szFeature : UInt16*,   # LPCWSTR
    pdwUseCount : UInt32*,   # DWORD* optional, out
    pwDateUsed : UInt16*   # WORD* optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiGetFeatureUsageWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint16>);
typedef MsiGetFeatureUsageWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint16>);
final MsiGetFeatureUsageW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiGetFeatureUsageWNative, MsiGetFeatureUsageWDart>('MsiGetFeatureUsageW');
// szProduct : LPCWSTR -> Pointer<Utf16>
// szFeature : LPCWSTR -> Pointer<Utf16>
// pdwUseCount : DWORD* optional, out -> Pointer<Uint32>
// pwDateUsed : WORD* optional, out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiGetFeatureUsageW(
  szProduct: PWideChar;   // LPCWSTR
  szFeature: PWideChar;   // LPCWSTR
  pdwUseCount: Pointer;   // DWORD* optional, out
  pwDateUsed: Pointer   // WORD* optional, out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetFeatureUsageW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiGetFeatureUsageW"
  c_MsiGetFeatureUsageW :: CWString -> CWString -> Ptr Word32 -> Ptr Word16 -> IO Word32
-- szProduct : LPCWSTR -> CWString
-- szFeature : LPCWSTR -> CWString
-- pdwUseCount : DWORD* optional, out -> Ptr Word32
-- pwDateUsed : WORD* optional, out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msigetfeatureusagew =
  foreign "MsiGetFeatureUsageW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* szProduct : LPCWSTR -> (ptr uint16_t) *)
(* szFeature : LPCWSTR -> (ptr uint16_t) *)
(* pdwUseCount : DWORD* optional, out -> (ptr uint32_t) *)
(* pwDateUsed : WORD* optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiGetFeatureUsageW" msi-get-feature-usage-w :convention :stdcall) :uint32
  (sz-product (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-feature (:string :encoding :utf-16le))   ; LPCWSTR
  (pdw-use-count :pointer)   ; DWORD* optional, out
  (pw-date-used :pointer))   ; WORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiGetFeatureUsageW = Win32::API::More->new('msi',
    'DWORD MsiGetFeatureUsageW(LPCWSTR szProduct, LPCWSTR szFeature, LPVOID pdwUseCount, LPVOID pwDateUsed)');
# my $ret = $MsiGetFeatureUsageW->Call($szProduct, $szFeature, $pdwUseCount, $pwDateUsed);
# szProduct : LPCWSTR -> LPCWSTR
# szFeature : LPCWSTR -> LPCWSTR
# pdwUseCount : DWORD* optional, out -> LPVOID
# pwDateUsed : WORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い