MsiGetSourcePathW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetSourcePathW(
MSIHANDLE hInstall,
LPCWSTR szFolder,
LPWSTR szPathBuf, // optional
DWORD* pcchPathBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに提供されるインストールへのハンドル、または MsiOpenPackage、MsiOpenPackageEx、MsiOpenProduct によって取得したハンドルです。 |
| szFolder | LPCWSTR | in | Directory テーブルのレコードを指定する null 終端文字列です。ディレクトリがルートディレクトリの場合、これは DefaultDir 列の値を指定できます。それ以外の場合は、Directory 列の値である必要があります。 |
| szPathBuf | LPWSTR | outoptional | null 終端された完全なソースパスを受け取るバッファーへのポインターです。szPathBuf に null (value=0) を渡してバッファーのサイズを判断しようとしないでください。バッファーのサイズは、空文字列(例: "")を渡すことで取得できます。その場合、関数は ERROR_MORE_DATA を返し、pcchPathBuf には終端の null 文字を含まない、必要なバッファーサイズが TCHAR 単位で格納されます。ERROR_SUCCESS が返された場合、pcchPathBuf には終端の null 文字を含まない、バッファーに書き込まれた TCHAR 数が格納されます。 |
| pcchPathBuf | DWORD* | inoutoptional | 変数 szPathBuf が指すバッファーのサイズを TCHAR 単位で指定する変数へのポインターです。関数が ERROR_SUCCESS を返すと、この変数には終端の null 文字を含まない、szPathBuf にコピーされたデータのサイズが格納されます。szPathBuf が十分な大きさでない場合、関数は ERROR_MORE_DATA を返し、終端の null 文字を含まない必要なサイズを pcchPathBuf が指す変数に格納します。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetSourcePath 関数は、Directory テーブル内のフォルダーの完全なソースパスを返します。(Unicode)
戻り値
MsiGetSourcePath 関数は次の値を返します。
解説(Remarks)
この関数を呼び出す前に、インストーラーはまず CostInitialize アクション、 FileCost アクション、 CostFinalize アクションを実行する必要があります。詳細については、Calling Database Functions from Programs を参照してください。
ERROR_MORE_DATA が返された場合、ポインターであるパラメーターは文字列を保持するために必要なバッファーのサイズを示します。ERROR_SUCCESS が返された場合は、文字列バッファーに書き込まれた文字数を示します。したがって、バッファーを指定するパラメーターに空文字列(例: "")を渡すことで、バッファーのサイズを取得できます。Null (value=0) を渡してバッファーのサイズを判断しようとしないでください。
関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
msiquery.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetSourcePath を定義します。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetSourcePathW(
MSIHANDLE hInstall,
LPCWSTR szFolder,
LPWSTR szPathBuf, // optional
DWORD* pcchPathBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetSourcePathW(
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 MsiGetSourcePathW(
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 MsiGetSourcePathW 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
MsiGetSourcePathW = ctypes.windll.msi.MsiGetSourcePathW
MsiGetSourcePathW.restype = wintypes.DWORD
MsiGetSourcePathW.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')
MsiGetSourcePathW = Fiddle::Function.new(
lib['MsiGetSourcePathW'],
[
-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 MsiGetSourcePathW(
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 MsiGetSourcePathW(uint hInstall, [MarshalAs(UnmanagedType.LPWStr)] string szFolder, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szPathBuf, IntPtr pcchPathBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetSourcePathW' -Namespace Win32 -PassThru
# $api::MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf)#uselib "msi.dll"
#func global MsiGetSourcePathW "MsiGetSourcePathW" wptr, wptr, wptr, wptr
; MsiGetSourcePathW 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 MsiGetSourcePathW "MsiGetSourcePathW" int, wstr, var, var ; res = MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf) ; hInstall : MSIHANDLE -> "int" ; szFolder : LPCWSTR -> "wstr" ; szPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetSourcePathW "MsiGetSourcePathW" int, wstr, sptr, sptr ; res = MsiGetSourcePathW(hInstall, szFolder, varptr(szPathBuf), varptr(pcchPathBuf)) ; hInstall : MSIHANDLE -> "int" ; szFolder : LPCWSTR -> "wstr" ; szPathBuf : LPWSTR optional, out -> "sptr" ; pcchPathBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetSourcePathW(MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR szPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiGetSourcePathW "MsiGetSourcePathW" int, wstr, var, var ; res = MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf) ; hInstall : MSIHANDLE -> "int" ; szFolder : LPCWSTR -> "wstr" ; szPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetSourcePathW(MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR szPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiGetSourcePathW "MsiGetSourcePathW" int, wstr, intptr, intptr ; res = MsiGetSourcePathW(hInstall, szFolder, varptr(szPathBuf), varptr(pcchPathBuf)) ; hInstall : MSIHANDLE -> "int" ; szFolder : LPCWSTR -> "wstr" ; szPathBuf : LPWSTR optional, out -> "intptr" ; pcchPathBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetSourcePathW = msi.NewProc("MsiGetSourcePathW")
)
// hInstall (MSIHANDLE), szFolder (LPCWSTR), szPathBuf (LPWSTR optional, out), pcchPathBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetSourcePathW.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFolder))),
uintptr(szPathBuf),
uintptr(pcchPathBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetSourcePathW(
hInstall: DWORD; // MSIHANDLE
szFolder: PWideChar; // LPCWSTR
szPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetSourcePathW';result := DllCall("msi\MsiGetSourcePathW"
, "UInt", hInstall ; MSIHANDLE
, "WStr", szFolder ; LPCWSTR
, "Ptr", szPathBuf ; LPWSTR optional, out
, "Ptr", pcchPathBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf) = DLL("msi.dll", "dword MsiGetSourcePathW(dword, char*, char*, void*)")
# 呼び出し: MsiGetSourcePathW(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 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetSourcePathW(
hInstall: u32, // MSIHANDLE
szFolder: [*c]const u16, // LPCWSTR
szPathBuf: [*c]u16, // LPWSTR optional, out
pcchPathBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetSourcePathW(
hInstall: uint32, # MSIHANDLE
szFolder: WideCString, # LPCWSTR
szPathBuf: ptr uint16, # LPWSTR optional, out
pcchPathBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetSourcePathW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetSourcePathW(
uint hInstall, // MSIHANDLE
const(wchar)* szFolder, // LPCWSTR
wchar* szPathBuf, // LPWSTR optional, out
uint* pcchPathBuf // DWORD* optional, in/out
);ccall((:MsiGetSourcePathW, "msi.dll"), stdcall, UInt32,
(UInt32, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
hInstall, szFolder, szPathBuf, pcchPathBuf)
# hInstall : MSIHANDLE -> UInt32
# szFolder : LPCWSTR -> Cwstring
# szPathBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchPathBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetSourcePathW(
uint32_t hInstall,
const uint16_t* szFolder,
uint16_t* szPathBuf,
uint32_t* pcchPathBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
-- hInstall : MSIHANDLE
-- szFolder : LPCWSTR
-- szPathBuf : LPWSTR optional, out
-- pcchPathBuf : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetSourcePathW = lib.func('__stdcall', 'MsiGetSourcePathW', 'uint32_t', ['uint32_t', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
// hInstall : MSIHANDLE -> 'uint32_t'
// szFolder : LPCWSTR -> 'str16'
// szPathBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchPathBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetSourcePathW: { parameters: ["u32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf)
// hInstall : MSIHANDLE -> "u32"
// szFolder : LPCWSTR -> "buffer"
// szPathBuf : LPWSTR optional, out -> "buffer"
// pcchPathBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetSourcePathW(
uint32_t hInstall,
const uint16_t* szFolder,
uint16_t* szPathBuf,
uint32_t* pcchPathBuf);
C, "msi.dll");
// $ffi->MsiGetSourcePathW(hInstall, szFolder, szPathBuf, pcchPathBuf);
// hInstall : MSIHANDLE
// szFolder : LPCWSTR
// szPathBuf : LPWSTR optional, out
// pcchPathBuf : DWORD* optional, in/out
// 構造体/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.UNICODE_OPTIONS);
int MsiGetSourcePathW(
int hInstall, // MSIHANDLE
WString szFolder, // LPCWSTR
char[] szPathBuf, // LPWSTR optional, out
IntByReference pcchPathBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetSourcePathW = MsiGetSourcePathW(
hInstall : UInt32, # MSIHANDLE
szFolder : UInt16*, # LPCWSTR
szPathBuf : UInt16*, # LPWSTR optional, out
pcchPathBuf : UInt32* # DWORD* optional, in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetSourcePathWNative = Uint32 Function(Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetSourcePathWDart = int Function(int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetSourcePathW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetSourcePathWNative, MsiGetSourcePathWDart>('MsiGetSourcePathW');
// hInstall : MSIHANDLE -> Uint32
// szFolder : LPCWSTR -> Pointer<Utf16>
// szPathBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchPathBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetSourcePathW(
hInstall: DWORD; // MSIHANDLE
szFolder: PWideChar; // LPCWSTR
szPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetSourcePathW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetSourcePathW"
c_MsiGetSourcePathW :: Word32 -> CWString -> CWString -> Ptr Word32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szFolder : LPCWSTR -> CWString
-- szPathBuf : LPWSTR optional, out -> CWString
-- pcchPathBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetsourcepathw =
foreign "MsiGetSourcePathW"
(uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szFolder : LPCWSTR -> (ptr uint16_t) *)
(* szPathBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchPathBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetSourcePathW" msi-get-source-path-w :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-folder (:string :encoding :utf-16le)) ; LPCWSTR
(sz-path-buf :pointer) ; LPWSTR optional, out
(pcch-path-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetSourcePathW = Win32::API::More->new('msi',
'DWORD MsiGetSourcePathW(DWORD hInstall, LPCWSTR szFolder, LPWSTR szPathBuf, LPVOID pcchPathBuf)');
# my $ret = $MsiGetSourcePathW->Call($hInstall, $szFolder, $szPathBuf, $pcchPathBuf);
# hInstall : MSIHANDLE -> DWORD
# szFolder : LPCWSTR -> LPCWSTR
# szPathBuf : LPWSTR optional, out -> LPWSTR
# pcchPathBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiGetSourcePathA (ANSI版) — フォルダーのソースパスを完全な形で取得する(ANSI版)。