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

MsiOpenProductA

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

シグネチャ

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiOpenProductA(
    LPCSTR szProduct,
    MSIHANDLE* hProduct
);

パラメーター

名前方向
szProductLPCSTRin
hProductMSIHANDLE*out

戻り値の型: DWORD

各言語での呼び出し定義

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiOpenProductA(
    LPCSTR szProduct,
    MSIHANDLE* hProduct
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiOpenProductA(
    [MarshalAs(UnmanagedType.LPStr)] string szProduct,   // LPCSTR
    out uint hProduct   // MSIHANDLE* out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiOpenProductA(
    <MarshalAs(UnmanagedType.LPStr)> szProduct As String,   ' LPCSTR
    <Out> ByRef hProduct As UInteger   ' MSIHANDLE* out
) As UInteger
End Function
' szProduct : LPCSTR
' hProduct : MSIHANDLE* out
Declare PtrSafe Function MsiOpenProductA Lib "msi" ( _
    ByVal szProduct As String, _
    ByRef hProduct As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiOpenProductA = msi.NewProc("MsiOpenProductA")
)

// szProduct (LPCSTR), hProduct (MSIHANDLE* out)
r1, _, err := procMsiOpenProductA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szProduct))),
	uintptr(hProduct),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiOpenProductA(
  szProduct: PAnsiChar;   // LPCSTR
  hProduct: Pointer   // MSIHANDLE* out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiOpenProductA';
result := DllCall("msi\MsiOpenProductA"
    , "AStr", szProduct   ; LPCSTR
    , "Ptr", hProduct   ; MSIHANDLE* out
    , "UInt")   ; return: DWORD
●MsiOpenProductA(szProduct, hProduct) = DLL("msi.dll", "dword MsiOpenProductA(char*, void*)")
# 呼び出し: MsiOpenProductA(szProduct, hProduct)
# szProduct : LPCSTR -> "char*"
# hProduct : MSIHANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。