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

MsiGetTargetPathW

関数
フォルダーのターゲットパスを完全な形で取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetTargetPathW(
    MSIHANDLE hInstall,
    LPCWSTR szFolder,
    LPWSTR szPathBuf,   // optional
    DWORD* pcchPathBuf   // optional
);

パラメーター

名前方向
hInstallMSIHANDLEin
szFolderLPCWSTRin
szPathBufLPWSTRoutoptional
pcchPathBufDWORD*inoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD MsiGetTargetPathW(
    MSIHANDLE hInstall,
    LPCWSTR szFolder,
    LPWSTR szPathBuf,   // optional
    DWORD* pcchPathBuf   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetTargetPathW(
    uint hInstall,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string szFolder,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szPathBuf,   // LPWSTR optional, out
    IntPtr pcchPathBuf   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetTargetPathW(
    hInstall As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPWStr)> szFolder As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szPathBuf As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchPathBuf As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' hInstall : MSIHANDLE
' szFolder : LPCWSTR
' szPathBuf : LPWSTR optional, out
' pcchPathBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetTargetPathW Lib "msi" ( _
    ByVal hInstall As Long, _
    ByVal szFolder As LongPtr, _
    ByVal szPathBuf As LongPtr, _
    ByVal pcchPathBuf 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

MsiGetTargetPathW = ctypes.windll.msi.MsiGetTargetPathW
MsiGetTargetPathW.restype = wintypes.DWORD
MsiGetTargetPathW.argtypes = [
    wintypes.DWORD,  # hInstall : MSIHANDLE
    wintypes.LPCWSTR,  # szFolder : LPCWSTR
    wintypes.LPWSTR,  # szPathBuf : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchPathBuf : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetTargetPathW = Fiddle::Function.new(
  lib['MsiGetTargetPathW'],
  [
    -Fiddle::TYPE_INT,  # hInstall : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szFolder : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szPathBuf : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchPathBuf : DWORD* optional, in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetTargetPathW(
        hInstall: u32,  // MSIHANDLE
        szFolder: *const u16,  // LPCWSTR
        szPathBuf: *mut u16,  // LPWSTR optional, out
        pcchPathBuf: *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 MsiGetTargetPathW(uint hInstall, [MarshalAs(UnmanagedType.LPWStr)] string szFolder, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szPathBuf, IntPtr pcchPathBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetTargetPathW' -Namespace Win32 -PassThru
# $api::MsiGetTargetPathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
#uselib "msi.dll"
#func global MsiGetTargetPathW "MsiGetTargetPathW" wptr, wptr, wptr, wptr
; MsiGetTargetPathW hInstall, szFolder, varptr(szPathBuf), varptr(pcchPathBuf)   ; 戻り値は stat
; hInstall : MSIHANDLE -> "wptr"
; szFolder : LPCWSTR -> "wptr"
; szPathBuf : LPWSTR optional, out -> "wptr"
; pcchPathBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetTargetPathW "MsiGetTargetPathW" int, wstr, var, var
; res = MsiGetTargetPathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
; hInstall : MSIHANDLE -> "int"
; szFolder : LPCWSTR -> "wstr"
; szPathBuf : LPWSTR optional, out -> "var"
; pcchPathBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR szPathBuf, DWORD* pcchPathBuf)
#uselib "msi.dll"
#cfunc global MsiGetTargetPathW "MsiGetTargetPathW" int, wstr, var, var
; res = MsiGetTargetPathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
; hInstall : MSIHANDLE -> "int"
; szFolder : LPCWSTR -> "wstr"
; szPathBuf : LPWSTR optional, out -> "var"
; pcchPathBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetTargetPathW = msi.NewProc("MsiGetTargetPathW")
)

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