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

MsiSetTargetPathW

関数
フォルダーのインストール先ターゲットパスを設定する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiSetTargetPathW(
    MSIHANDLE hInstall,
    LPCWSTR szFolder,
    LPCWSTR szFolderPath
);

パラメーター

名前方向説明
hInstallMSIHANDLEin実行中インストールセッションのハンドルを指定する。
szFolderLPCWSTRinパスを変更するフォルダのDirectoryテーブルキー(Unicode)を指定する。
szFolderPathLPCWSTRin新たに設定するターゲットフォルダのフルパス(Unicode)を指定する。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

MsiSetTargetPathW = ctypes.windll.msi.MsiSetTargetPathW
MsiSetTargetPathW.restype = wintypes.DWORD
MsiSetTargetPathW.argtypes = [
    wintypes.DWORD,  # hInstall : MSIHANDLE
    wintypes.LPCWSTR,  # szFolder : LPCWSTR
    wintypes.LPCWSTR,  # szFolderPath : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiSetTargetPathW = msi.NewProc("MsiSetTargetPathW")
)

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