MsiGetProductPropertyW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductPropertyW(
MSIHANDLE hProduct,
LPCWSTR szProperty,
LPWSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hProduct | MSIHANDLE | in | MsiOpenProduct から取得した製品のハンドル。 |
| szProperty | LPCWSTR | in | 取得するプロパティを指定します。大文字と小文字が区別されます。 |
| lpValueBuf | LPWSTR | outoptional | プロパティ値を受け取るバッファーへのポインター。lpValueBuf が小さすぎる場合、値は切り詰められ、null で終端されます。このパラメーターは null を指定できます。 |
| pcchValueBuf | DWORD* | inoutoptional | lpValueBuf パラメーターが指すバッファーのサイズ(文字数)を指定する変数へのポインター。入力時には、終端の null 文字分の領域を含むバッファーの全サイズを指定します。渡したバッファーが小さすぎる場合、返される文字数には終端の null 文字は含まれません。 lpValueBuf が null の場合、pcchValueBuf は null を指定できます。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetProductProperty 関数は、製品のプロパティを取得します。これらのプロパティは製品データベースに格納されています。(Unicode)
戻り値
<b>MsiGetProductProperty</b> 関数は、次の値を返します。
| 値 | 意味 |
|---|---|
| 無効なパラメーターが関数に渡されました。 | |
| 無効なハンドルが関数に渡されました。 | |
| プロパティ値全体を格納するにはバッファーが小さすぎます。 | |
| 関数は正常に完了しました。 |
解説(Remarks)
MsiGetProductProperty 関数が返ると、pcchValueBuf パラメーターにはバッファーに格納された文字列の長さが入ります。返される文字数には終端の null 文字は含まれません。バッファーが十分な大きさでない場合、 MsiGetProductProperty は ERROR_MORE_DATA を返し、 MsiGetProductProperty には null 文字を数えない文字列のサイズ(文字数)が入ります。
msi.h ヘッダーは MsiGetProductProperty を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディングに依存しないこのエイリアスの使用を、エンコーディングに依存しないわけではないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合につながる可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductPropertyW(
MSIHANDLE hProduct,
LPCWSTR szProperty,
LPWSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetProductPropertyW(
uint hProduct, // MSIHANDLE
[MarshalAs(UnmanagedType.LPWStr)] string szProperty, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValueBuf, // LPWSTR optional, out
IntPtr pcchValueBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetProductPropertyW(
hProduct As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPWStr)> szProperty As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpValueBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchValueBuf As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' hProduct : MSIHANDLE
' szProperty : LPCWSTR
' lpValueBuf : LPWSTR optional, out
' pcchValueBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetProductPropertyW Lib "msi" ( _
ByVal hProduct As Long, _
ByVal szProperty As LongPtr, _
ByVal lpValueBuf As LongPtr, _
ByVal pcchValueBuf 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
MsiGetProductPropertyW = ctypes.windll.msi.MsiGetProductPropertyW
MsiGetProductPropertyW.restype = wintypes.DWORD
MsiGetProductPropertyW.argtypes = [
wintypes.DWORD, # hProduct : MSIHANDLE
wintypes.LPCWSTR, # szProperty : LPCWSTR
wintypes.LPWSTR, # lpValueBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchValueBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductPropertyW = Fiddle::Function.new(
lib['MsiGetProductPropertyW'],
[
-Fiddle::TYPE_INT, # hProduct : MSIHANDLE
Fiddle::TYPE_VOIDP, # szProperty : LPCWSTR
Fiddle::TYPE_VOIDP, # lpValueBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchValueBuf : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetProductPropertyW(
hProduct: u32, // MSIHANDLE
szProperty: *const u16, // LPCWSTR
lpValueBuf: *mut u16, // LPWSTR optional, out
pcchValueBuf: *mut u32 // DWORD* optional, in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetProductPropertyW(uint hProduct, [MarshalAs(UnmanagedType.LPWStr)] string szProperty, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValueBuf, IntPtr pcchValueBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductPropertyW' -Namespace Win32 -PassThru
# $api::MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf)#uselib "msi.dll"
#func global MsiGetProductPropertyW "MsiGetProductPropertyW" wptr, wptr, wptr, wptr
; MsiGetProductPropertyW hProduct, szProperty, varptr(lpValueBuf), varptr(pcchValueBuf) ; 戻り値は stat
; hProduct : MSIHANDLE -> "wptr"
; szProperty : LPCWSTR -> "wptr"
; lpValueBuf : LPWSTR optional, out -> "wptr"
; pcchValueBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetProductPropertyW "MsiGetProductPropertyW" int, wstr, var, var ; res = MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf) ; hProduct : MSIHANDLE -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductPropertyW "MsiGetProductPropertyW" int, wstr, sptr, sptr ; res = MsiGetProductPropertyW(hProduct, szProperty, varptr(lpValueBuf), varptr(pcchValueBuf)) ; hProduct : MSIHANDLE -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "sptr" ; pcchValueBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty, LPWSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetProductPropertyW "MsiGetProductPropertyW" int, wstr, var, var ; res = MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf) ; hProduct : MSIHANDLE -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty, LPWSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetProductPropertyW "MsiGetProductPropertyW" int, wstr, intptr, intptr ; res = MsiGetProductPropertyW(hProduct, szProperty, varptr(lpValueBuf), varptr(pcchValueBuf)) ; hProduct : MSIHANDLE -> "int" ; szProperty : LPCWSTR -> "wstr" ; lpValueBuf : LPWSTR optional, out -> "intptr" ; pcchValueBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductPropertyW = msi.NewProc("MsiGetProductPropertyW")
)
// hProduct (MSIHANDLE), szProperty (LPCWSTR), lpValueBuf (LPWSTR optional, out), pcchValueBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetProductPropertyW.Call(
uintptr(hProduct),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProperty))),
uintptr(lpValueBuf),
uintptr(pcchValueBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductPropertyW(
hProduct: DWORD; // MSIHANDLE
szProperty: PWideChar; // LPCWSTR
lpValueBuf: PWideChar; // LPWSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductPropertyW';result := DllCall("msi\MsiGetProductPropertyW"
, "UInt", hProduct ; MSIHANDLE
, "WStr", szProperty ; LPCWSTR
, "Ptr", lpValueBuf ; LPWSTR optional, out
, "Ptr", pcchValueBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf) = DLL("msi.dll", "dword MsiGetProductPropertyW(dword, char*, char*, void*)")
# 呼び出し: MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf)
# hProduct : MSIHANDLE -> "dword"
# szProperty : LPCWSTR -> "char*"
# lpValueBuf : LPWSTR optional, out -> "char*"
# pcchValueBuf : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetProductPropertyW(
hProduct: u32, // MSIHANDLE
szProperty: [*c]const u16, // LPCWSTR
lpValueBuf: [*c]u16, // LPWSTR optional, out
pcchValueBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetProductPropertyW(
hProduct: uint32, # MSIHANDLE
szProperty: WideCString, # LPCWSTR
lpValueBuf: ptr uint16, # LPWSTR optional, out
pcchValueBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetProductPropertyW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetProductPropertyW(
uint hProduct, // MSIHANDLE
const(wchar)* szProperty, // LPCWSTR
wchar* lpValueBuf, // LPWSTR optional, out
uint* pcchValueBuf // DWORD* optional, in/out
);ccall((:MsiGetProductPropertyW, "msi.dll"), stdcall, UInt32,
(UInt32, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
hProduct, szProperty, lpValueBuf, pcchValueBuf)
# hProduct : MSIHANDLE -> UInt32
# szProperty : LPCWSTR -> Cwstring
# lpValueBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchValueBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetProductPropertyW(
uint32_t hProduct,
const uint16_t* szProperty,
uint16_t* lpValueBuf,
uint32_t* pcchValueBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf)
-- hProduct : MSIHANDLE
-- szProperty : LPCWSTR
-- lpValueBuf : LPWSTR optional, out
-- pcchValueBuf : DWORD* optional, in/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 MsiGetProductPropertyW = lib.func('__stdcall', 'MsiGetProductPropertyW', 'uint32_t', ['uint32_t', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf)
// hProduct : MSIHANDLE -> 'uint32_t'
// szProperty : LPCWSTR -> 'str16'
// lpValueBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchValueBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetProductPropertyW: { parameters: ["u32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf)
// hProduct : MSIHANDLE -> "u32"
// szProperty : LPCWSTR -> "buffer"
// lpValueBuf : LPWSTR optional, out -> "buffer"
// pcchValueBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetProductPropertyW(
uint32_t hProduct,
const uint16_t* szProperty,
uint16_t* lpValueBuf,
uint32_t* pcchValueBuf);
C, "msi.dll");
// $ffi->MsiGetProductPropertyW(hProduct, szProperty, lpValueBuf, pcchValueBuf);
// hProduct : MSIHANDLE
// szProperty : LPCWSTR
// lpValueBuf : LPWSTR optional, out
// pcchValueBuf : DWORD* optional, in/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 MsiGetProductPropertyW(
int hProduct, // MSIHANDLE
WString szProperty, // LPCWSTR
char[] lpValueBuf, // LPWSTR optional, out
IntByReference pcchValueBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetProductPropertyW = MsiGetProductPropertyW(
hProduct : UInt32, # MSIHANDLE
szProperty : UInt16*, # LPCWSTR
lpValueBuf : UInt16*, # LPWSTR optional, out
pcchValueBuf : UInt32* # DWORD* optional, in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetProductPropertyWNative = Uint32 Function(Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetProductPropertyWDart = int Function(int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetProductPropertyW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetProductPropertyWNative, MsiGetProductPropertyWDart>('MsiGetProductPropertyW');
// hProduct : MSIHANDLE -> Uint32
// szProperty : LPCWSTR -> Pointer<Utf16>
// lpValueBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchValueBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetProductPropertyW(
hProduct: DWORD; // MSIHANDLE
szProperty: PWideChar; // LPCWSTR
lpValueBuf: PWideChar; // LPWSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductPropertyW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetProductPropertyW"
c_MsiGetProductPropertyW :: Word32 -> CWString -> CWString -> Ptr Word32 -> IO Word32
-- hProduct : MSIHANDLE -> Word32
-- szProperty : LPCWSTR -> CWString
-- lpValueBuf : LPWSTR optional, out -> CWString
-- pcchValueBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetproductpropertyw =
foreign "MsiGetProductPropertyW"
(uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* hProduct : MSIHANDLE -> uint32_t *)
(* szProperty : LPCWSTR -> (ptr uint16_t) *)
(* lpValueBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchValueBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetProductPropertyW" msi-get-product-property-w :convention :stdcall) :uint32
(h-product :uint32) ; MSIHANDLE
(sz-property (:string :encoding :utf-16le)) ; LPCWSTR
(lp-value-buf :pointer) ; LPWSTR optional, out
(pcch-value-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetProductPropertyW = Win32::API::More->new('msi',
'DWORD MsiGetProductPropertyW(DWORD hProduct, LPCWSTR szProperty, LPWSTR lpValueBuf, LPVOID pcchValueBuf)');
# my $ret = $MsiGetProductPropertyW->Call($hProduct, $szProperty, $lpValueBuf, $pcchValueBuf);
# hProduct : MSIHANDLE -> DWORD
# szProperty : LPCWSTR -> LPCWSTR
# lpValueBuf : LPWSTR optional, out -> LPWSTR
# pcchValueBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiGetProductPropertyA (ANSI版) — 開いた製品ハンドルから指定プロパティの値を取得する。