MsiSetTargetPathA
関数シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSetTargetPathA(
MSIHANDLE hInstall,
LPCSTR szFolder,
LPCSTR szFolderPath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに提供された、または MsiOpenPackage、MsiOpenPackageEx、MsiOpenProduct によって取得したインストールへのハンドル。 |
| szFolder | LPCSTR | in | フォルダー識別子を指定します。これは Directory テーブルの主キーです。 |
| szFolderPath | LPCSTR | in | フォルダーの完全なパスを指定します。末尾はディレクトリ区切り文字で終わります。 |
戻り値の型: DWORD
公式ドキュメント
MsiSetTargetPath 関数は、Directory テーブル内のフォルダーに対する完全なターゲットパスを設定します。(ANSI)
戻り値
MsiSetTargetPath 関数は次の値を返します。
解説(Remarks)
MsiSetTargetPath 関数は、メモリ内の Directory テーブル で指定されたターゲットディレクトリのパス指定を変更します。また、テーブル内で変更されたパスに従属する、または等価なその他すべてのパスオブジェクトのパス指定も、変更を反映するように更新されます。影響を受ける各パスのプロパティも更新されます。
選択したディレクトリが読み取り専用の場合、MsiSetTargetPath は失敗します。
この関数でエラーが発生した場合、更新されたすべてのパスとプロパティは以前の値に戻ります。したがって、この関数が返すエラーは致命的でないものとして扱って差し支えありません。
対象のパスを使用するコンポーネントが、現在のユーザーまたは別のユーザーに対してすでにインストールされている場合は、ターゲットパスを設定しようとしないでください。MsiSetTargetPath を呼び出す前に ProductState プロパティを確認し、このコンポーネントを含む製品がインストールされているかどうかを判断してください。
Calling Database Functions From Programs を参照してください。
この関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
msiquery.h ヘッダーは MsiSetTargetPath をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiSetTargetPathA(
MSIHANDLE hInstall,
LPCSTR szFolder,
LPCSTR szFolderPath
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiSetTargetPathA(
uint hInstall, // MSIHANDLE
[MarshalAs(UnmanagedType.LPStr)] string szFolder, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szFolderPath // LPCSTR
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiSetTargetPathA(
hInstall As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPStr)> szFolder As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szFolderPath As String ' LPCSTR
) As UInteger
End Function' hInstall : MSIHANDLE
' szFolder : LPCSTR
' szFolderPath : LPCSTR
Declare PtrSafe Function MsiSetTargetPathA Lib "msi" ( _
ByVal hInstall As Long, _
ByVal szFolder As String, _
ByVal szFolderPath As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiSetTargetPathA = ctypes.windll.msi.MsiSetTargetPathA
MsiSetTargetPathA.restype = wintypes.DWORD
MsiSetTargetPathA.argtypes = [
wintypes.DWORD, # hInstall : MSIHANDLE
wintypes.LPCSTR, # szFolder : LPCSTR
wintypes.LPCSTR, # szFolderPath : LPCSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiSetTargetPathA = Fiddle::Function.new(
lib['MsiSetTargetPathA'],
[
-Fiddle::TYPE_INT, # hInstall : MSIHANDLE
Fiddle::TYPE_VOIDP, # szFolder : LPCSTR
Fiddle::TYPE_VOIDP, # szFolderPath : LPCSTR
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiSetTargetPathA(
hInstall: u32, // MSIHANDLE
szFolder: *const u8, // LPCSTR
szFolderPath: *const u8 // LPCSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiSetTargetPathA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szFolder, [MarshalAs(UnmanagedType.LPStr)] string szFolderPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiSetTargetPathA' -Namespace Win32 -PassThru
# $api::MsiSetTargetPathA(hInstall, szFolder, szFolderPath)#uselib "msi.dll"
#func global MsiSetTargetPathA "MsiSetTargetPathA" sptr, sptr, sptr
; MsiSetTargetPathA hInstall, szFolder, szFolderPath ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szFolder : LPCSTR -> "sptr"
; szFolderPath : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll"
#cfunc global MsiSetTargetPathA "MsiSetTargetPathA" int, str, str
; res = MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
; hInstall : MSIHANDLE -> "int"
; szFolder : LPCSTR -> "str"
; szFolderPath : LPCSTR -> "str"; DWORD MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder, LPCSTR szFolderPath)
#uselib "msi.dll"
#cfunc global MsiSetTargetPathA "MsiSetTargetPathA" int, str, str
; res = MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
; hInstall : MSIHANDLE -> "int"
; szFolder : LPCSTR -> "str"
; szFolderPath : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiSetTargetPathA = msi.NewProc("MsiSetTargetPathA")
)
// hInstall (MSIHANDLE), szFolder (LPCSTR), szFolderPath (LPCSTR)
r1, _, err := procMsiSetTargetPathA.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szFolder))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szFolderPath))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiSetTargetPathA(
hInstall: DWORD; // MSIHANDLE
szFolder: PAnsiChar; // LPCSTR
szFolderPath: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiSetTargetPathA';result := DllCall("msi\MsiSetTargetPathA"
, "UInt", hInstall ; MSIHANDLE
, "AStr", szFolder ; LPCSTR
, "AStr", szFolderPath ; LPCSTR
, "UInt") ; return: DWORD●MsiSetTargetPathA(hInstall, szFolder, szFolderPath) = DLL("msi.dll", "dword MsiSetTargetPathA(dword, char*, char*)")
# 呼び出し: MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
# hInstall : MSIHANDLE -> "dword"
# szFolder : LPCSTR -> "char*"
# szFolderPath : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiSetTargetPathA(
hInstall: u32, // MSIHANDLE
szFolder: [*c]const u8, // LPCSTR
szFolderPath: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) u32;proc MsiSetTargetPathA(
hInstall: uint32, # MSIHANDLE
szFolder: cstring, # LPCSTR
szFolderPath: cstring # LPCSTR
): uint32 {.importc: "MsiSetTargetPathA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiSetTargetPathA(
uint hInstall, // MSIHANDLE
const(char)* szFolder, // LPCSTR
const(char)* szFolderPath // LPCSTR
);ccall((:MsiSetTargetPathA, "msi.dll"), stdcall, UInt32,
(UInt32, Cstring, Cstring),
hInstall, szFolder, szFolderPath)
# hInstall : MSIHANDLE -> UInt32
# szFolder : LPCSTR -> Cstring
# szFolderPath : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiSetTargetPathA(
uint32_t hInstall,
const char* szFolder,
const char* szFolderPath);
]]
local msi = ffi.load("msi")
-- msi.MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
-- hInstall : MSIHANDLE
-- szFolder : LPCSTR
-- szFolderPath : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiSetTargetPathA = lib.func('__stdcall', 'MsiSetTargetPathA', 'uint32_t', ['uint32_t', 'str', 'str']);
// MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
// hInstall : MSIHANDLE -> 'uint32_t'
// szFolder : LPCSTR -> 'str'
// szFolderPath : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiSetTargetPathA: { parameters: ["u32", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiSetTargetPathA(hInstall, szFolder, szFolderPath)
// hInstall : MSIHANDLE -> "u32"
// szFolder : LPCSTR -> "buffer"
// szFolderPath : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiSetTargetPathA(
uint32_t hInstall,
const char* szFolder,
const char* szFolderPath);
C, "msi.dll");
// $ffi->MsiSetTargetPathA(hInstall, szFolder, szFolderPath);
// hInstall : MSIHANDLE
// szFolder : LPCSTR
// szFolderPath : LPCSTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Msi extends StdCallLibrary {
Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
int MsiSetTargetPathA(
int hInstall, // MSIHANDLE
String szFolder, // LPCSTR
String szFolderPath // LPCSTR
);
}@[Link("msi")]
lib Libmsi
fun MsiSetTargetPathA = MsiSetTargetPathA(
hInstall : UInt32, # MSIHANDLE
szFolder : UInt8*, # LPCSTR
szFolderPath : UInt8* # LPCSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiSetTargetPathANative = Uint32 Function(Uint32, Pointer<Utf8>, Pointer<Utf8>);
typedef MsiSetTargetPathADart = int Function(int, Pointer<Utf8>, Pointer<Utf8>);
final MsiSetTargetPathA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiSetTargetPathANative, MsiSetTargetPathADart>('MsiSetTargetPathA');
// hInstall : MSIHANDLE -> Uint32
// szFolder : LPCSTR -> Pointer<Utf8>
// szFolderPath : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiSetTargetPathA(
hInstall: DWORD; // MSIHANDLE
szFolder: PAnsiChar; // LPCSTR
szFolderPath: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'msi.dll' name 'MsiSetTargetPathA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiSetTargetPathA"
c_MsiSetTargetPathA :: Word32 -> CString -> CString -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szFolder : LPCSTR -> CString
-- szFolderPath : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msisettargetpatha =
foreign "MsiSetTargetPathA"
(uint32_t @-> string @-> string @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szFolder : LPCSTR -> string *)
(* szFolderPath : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiSetTargetPathA" msi-set-target-path-a :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-folder :string) ; LPCSTR
(sz-folder-path :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiSetTargetPathA = Win32::API::More->new('msi',
'DWORD MsiSetTargetPathA(DWORD hInstall, LPCSTR szFolder, LPCSTR szFolderPath)');
# my $ret = $MsiSetTargetPathA->Call($hInstall, $szFolder, $szFolderPath);
# hInstall : MSIHANDLE -> DWORD
# szFolder : LPCSTR -> LPCSTR
# szFolderPath : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f MsiSetTargetPathW (Unicode版) — フォルダーのインストール先ターゲットパスを設定する(Unicode版)。