ホーム › System.ApplicationInstallationAndServicing › MsiGetProductCodeW
MsiGetProductCodeW
関数コンポーネントから所属製品コードを取得する(Unicode版)。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductCodeW(
LPCWSTR szComponent,
LPWSTR lpBuf39
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| szComponent | LPCWSTR | in |
| lpBuf39 | LPWSTR | out |
戻り値の型: DWORD
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductCodeW(
LPCWSTR szComponent,
LPWSTR lpBuf39
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetProductCodeW(
[MarshalAs(UnmanagedType.LPWStr)] string szComponent, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuf39 // LPWSTR out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetProductCodeW(
<MarshalAs(UnmanagedType.LPWStr)> szComponent As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpBuf39 As System.Text.StringBuilder ' LPWSTR out
) As UInteger
End Function' szComponent : LPCWSTR
' lpBuf39 : LPWSTR out
Declare PtrSafe Function MsiGetProductCodeW Lib "msi" ( _
ByVal szComponent As LongPtr, _
ByVal lpBuf39 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
MsiGetProductCodeW = ctypes.windll.msi.MsiGetProductCodeW
MsiGetProductCodeW.restype = wintypes.DWORD
MsiGetProductCodeW.argtypes = [
wintypes.LPCWSTR, # szComponent : LPCWSTR
wintypes.LPWSTR, # lpBuf39 : LPWSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductCodeW = Fiddle::Function.new(
lib['MsiGetProductCodeW'],
[
Fiddle::TYPE_VOIDP, # szComponent : LPCWSTR
Fiddle::TYPE_VOIDP, # lpBuf39 : LPWSTR out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetProductCodeW(
szComponent: *const u16, // LPCWSTR
lpBuf39: *mut u16 // LPWSTR out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetProductCodeW([MarshalAs(UnmanagedType.LPWStr)] string szComponent, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuf39);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductCodeW' -Namespace Win32 -PassThru
# $api::MsiGetProductCodeW(szComponent, lpBuf39)#uselib "msi.dll"
#func global MsiGetProductCodeW "MsiGetProductCodeW" wptr, wptr
; MsiGetProductCodeW szComponent, varptr(lpBuf39) ; 戻り値は stat
; szComponent : LPCWSTR -> "wptr"
; lpBuf39 : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, var ; res = MsiGetProductCodeW(szComponent, lpBuf39) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, sptr ; res = MsiGetProductCodeW(szComponent, varptr(lpBuf39)) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, var ; res = MsiGetProductCodeW(szComponent, lpBuf39) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, intptr ; res = MsiGetProductCodeW(szComponent, varptr(lpBuf39)) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductCodeW = msi.NewProc("MsiGetProductCodeW")
)
// szComponent (LPCWSTR), lpBuf39 (LPWSTR out)
r1, _, err := procMsiGetProductCodeW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
uintptr(lpBuf39),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductCodeW(
szComponent: PWideChar; // LPCWSTR
lpBuf39: PWideChar // LPWSTR out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductCodeW';result := DllCall("msi\MsiGetProductCodeW"
, "WStr", szComponent ; LPCWSTR
, "Ptr", lpBuf39 ; LPWSTR out
, "UInt") ; return: DWORD●MsiGetProductCodeW(szComponent, lpBuf39) = DLL("msi.dll", "dword MsiGetProductCodeW(char*, char*)")
# 呼び出し: MsiGetProductCodeW(szComponent, lpBuf39)
# szComponent : LPCWSTR -> "char*"
# lpBuf39 : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。