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

MsiGetShortcutTargetW

関数
ショートカットから製品、フィーチャー、コンポーネントの情報を取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetShortcutTargetW(
    LPCWSTR szShortcutPath,
    LPWSTR szProductCode,   // optional
    LPWSTR szFeatureId,   // optional
    LPWSTR szComponentCode   // optional
);

パラメーター

名前方向
szShortcutPathLPCWSTRin
szProductCodeLPWSTRoutoptional
szFeatureIdLPWSTRoutoptional
szComponentCodeLPWSTRoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD MsiGetShortcutTargetW(
    LPCWSTR szShortcutPath,
    LPWSTR szProductCode,   // optional
    LPWSTR szFeatureId,   // optional
    LPWSTR szComponentCode   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetShortcutTargetW(
    [MarshalAs(UnmanagedType.LPWStr)] string szShortcutPath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szProductCode,   // LPWSTR optional, out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szFeatureId,   // LPWSTR optional, out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szComponentCode   // LPWSTR optional, out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetShortcutTargetW(
    <MarshalAs(UnmanagedType.LPWStr)> szShortcutPath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szProductCode As System.Text.StringBuilder,   ' LPWSTR optional, out
    <MarshalAs(UnmanagedType.LPWStr)> szFeatureId As System.Text.StringBuilder,   ' LPWSTR optional, out
    <MarshalAs(UnmanagedType.LPWStr)> szComponentCode As System.Text.StringBuilder   ' LPWSTR optional, out
) As UInteger
End Function
' szShortcutPath : LPCWSTR
' szProductCode : LPWSTR optional, out
' szFeatureId : LPWSTR optional, out
' szComponentCode : LPWSTR optional, out
Declare PtrSafe Function MsiGetShortcutTargetW Lib "msi" ( _
    ByVal szShortcutPath As LongPtr, _
    ByVal szProductCode As LongPtr, _
    ByVal szFeatureId As LongPtr, _
    ByVal szComponentCode 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

MsiGetShortcutTargetW = ctypes.windll.msi.MsiGetShortcutTargetW
MsiGetShortcutTargetW.restype = wintypes.DWORD
MsiGetShortcutTargetW.argtypes = [
    wintypes.LPCWSTR,  # szShortcutPath : LPCWSTR
    wintypes.LPWSTR,  # szProductCode : LPWSTR optional, out
    wintypes.LPWSTR,  # szFeatureId : LPWSTR optional, out
    wintypes.LPWSTR,  # szComponentCode : LPWSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetShortcutTargetW = Fiddle::Function.new(
  lib['MsiGetShortcutTargetW'],
  [
    Fiddle::TYPE_VOIDP,  # szShortcutPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szProductCode : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # szFeatureId : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # szComponentCode : LPWSTR optional, out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetShortcutTargetW(
        szShortcutPath: *const u16,  // LPCWSTR
        szProductCode: *mut u16,  // LPWSTR optional, out
        szFeatureId: *mut u16,  // LPWSTR optional, out
        szComponentCode: *mut u16  // LPWSTR optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetShortcutTargetW([MarshalAs(UnmanagedType.LPWStr)] string szShortcutPath, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szProductCode, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szFeatureId, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szComponentCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetShortcutTargetW' -Namespace Win32 -PassThru
# $api::MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
#uselib "msi.dll"
#func global MsiGetShortcutTargetW "MsiGetShortcutTargetW" wptr, wptr, wptr, wptr
; MsiGetShortcutTargetW szShortcutPath, varptr(szProductCode), varptr(szFeatureId), varptr(szComponentCode)   ; 戻り値は stat
; szShortcutPath : LPCWSTR -> "wptr"
; szProductCode : LPWSTR optional, out -> "wptr"
; szFeatureId : LPWSTR optional, out -> "wptr"
; szComponentCode : LPWSTR optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetShortcutTargetW "MsiGetShortcutTargetW" wstr, var, var, var
; res = MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
; szShortcutPath : LPCWSTR -> "wstr"
; szProductCode : LPWSTR optional, out -> "var"
; szFeatureId : LPWSTR optional, out -> "var"
; szComponentCode : LPWSTR optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetShortcutTargetW(LPCWSTR szShortcutPath, LPWSTR szProductCode, LPWSTR szFeatureId, LPWSTR szComponentCode)
#uselib "msi.dll"
#cfunc global MsiGetShortcutTargetW "MsiGetShortcutTargetW" wstr, var, var, var
; res = MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
; szShortcutPath : LPCWSTR -> "wstr"
; szProductCode : LPWSTR optional, out -> "var"
; szFeatureId : LPWSTR optional, out -> "var"
; szComponentCode : LPWSTR optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetShortcutTargetW = msi.NewProc("MsiGetShortcutTargetW")
)

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