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

MsiOpenProductW

関数
インストール済み製品をクエリ用に開いてハンドルを取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiOpenProductW(
    LPCWSTR szProduct,
    MSIHANDLE* hProduct
);

パラメーター

名前方向
szProductLPCWSTRin
hProductMSIHANDLE*out

戻り値の型: DWORD

各言語での呼び出し定義

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

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

MsiOpenProductW = ctypes.windll.msi.MsiOpenProductW
MsiOpenProductW.restype = wintypes.DWORD
MsiOpenProductW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    ctypes.c_void_p,  # hProduct : MSIHANDLE* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiOpenProductW = msi.NewProc("MsiOpenProductW")
)

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