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ショートカットへのフルパスを指定する、null で終わる文字列です。
szProductCodeLPWSTRoutoptionalショートカットの製品コードを表す GUID です。この文字列バッファは 39 文字分の長さが必要です。最初の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。このパラメーターは null にできます。
szFeatureIdLPWSTRoutoptionalショートカットの機能名です。文字列バッファは MAX_FEATURE_CHARS+1 文字分の長さが必要です。このパラメーターは null にできます。
szComponentCodeLPWSTRoutoptionalコンポーネントコードを表す GUID です。この文字列バッファは 39 文字分の長さが必要です。最初の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。このパラメーターは null にできます。

戻り値の型: DWORD

公式ドキュメント

MsiGetShortcutTarget 関数はショートカットを調べ、利用可能であればその製品、機能名、コンポーネントを返します。(Unicode)

戻り値

この関数は UINT を返します。

解説(Remarks)

関数が失敗し、かつショートカットが存在する場合は、ショートカットの通常の内容に IShellLink インターフェイスを通じてアクセスできます。

それ以外の場合は、 Installer Selection Functions を使用してターゲットの状態を判別できます。

メモ

msi.h ヘッダーは MsiGetShortcutTarget を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存ではないコードと混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 版の利用を推奨。
const std = @import("std");

extern "msi" fn MsiGetShortcutTargetW(
    szShortcutPath: [*c]const u16, // LPCWSTR
    szProductCode: [*c]u16, // LPWSTR optional, out
    szFeatureId: [*c]u16, // LPWSTR optional, out
    szComponentCode: [*c]u16 // LPWSTR optional, out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiGetShortcutTargetW(
    szShortcutPath: WideCString,  # LPCWSTR
    szProductCode: ptr uint16,  # LPWSTR optional, out
    szFeatureId: ptr uint16,  # LPWSTR optional, out
    szComponentCode: ptr uint16  # LPWSTR optional, out
): uint32 {.importc: "MsiGetShortcutTargetW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiGetShortcutTargetW(
    const(wchar)* szShortcutPath,   // LPCWSTR
    wchar* szProductCode,   // LPWSTR optional, out
    wchar* szFeatureId,   // LPWSTR optional, out
    wchar* szComponentCode   // LPWSTR optional, out
);
ccall((:MsiGetShortcutTargetW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Ptr{UInt16}, Ptr{UInt16}, Ptr{UInt16}),
      szShortcutPath, szProductCode, szFeatureId, szComponentCode)
# szShortcutPath : LPCWSTR -> Cwstring
# szProductCode : LPWSTR optional, out -> Ptr{UInt16}
# szFeatureId : LPWSTR optional, out -> Ptr{UInt16}
# szComponentCode : LPWSTR optional, out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetShortcutTargetW(
    const uint16_t* szShortcutPath,
    uint16_t* szProductCode,
    uint16_t* szFeatureId,
    uint16_t* szComponentCode);
]]
local msi = ffi.load("msi")
-- msi.MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
-- szShortcutPath : LPCWSTR
-- szProductCode : LPWSTR optional, out
-- szFeatureId : LPWSTR optional, out
-- szComponentCode : LPWSTR optional, 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 MsiGetShortcutTargetW = lib.func('__stdcall', 'MsiGetShortcutTargetW', 'uint32_t', ['str16', 'uint16_t *', 'uint16_t *', 'uint16_t *']);
// MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
// szShortcutPath : LPCWSTR -> 'str16'
// szProductCode : LPWSTR optional, out -> 'uint16_t *'
// szFeatureId : LPWSTR optional, out -> 'uint16_t *'
// szComponentCode : LPWSTR optional, out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiGetShortcutTargetW: { parameters: ["buffer", "buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
// szShortcutPath : LPCWSTR -> "buffer"
// szProductCode : LPWSTR optional, out -> "buffer"
// szFeatureId : LPWSTR optional, out -> "buffer"
// szComponentCode : LPWSTR optional, out -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetShortcutTargetW(
    const uint16_t* szShortcutPath,
    uint16_t* szProductCode,
    uint16_t* szFeatureId,
    uint16_t* szComponentCode);
C, "msi.dll");
// $ffi->MsiGetShortcutTargetW(szShortcutPath, szProductCode, szFeatureId, szComponentCode);
// szShortcutPath : LPCWSTR
// szProductCode : LPWSTR optional, out
// szFeatureId : LPWSTR optional, out
// szComponentCode : LPWSTR optional, 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 MsiGetShortcutTargetW(
        WString szShortcutPath,   // LPCWSTR
        char[] szProductCode,   // LPWSTR optional, out
        char[] szFeatureId,   // LPWSTR optional, out
        char[] szComponentCode   // LPWSTR optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiGetShortcutTargetW = MsiGetShortcutTargetW(
    szShortcutPath : UInt16*,   # LPCWSTR
    szProductCode : UInt16*,   # LPWSTR optional, out
    szFeatureId : UInt16*,   # LPWSTR optional, out
    szComponentCode : UInt16*   # LPWSTR optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiGetShortcutTargetWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef MsiGetShortcutTargetWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final MsiGetShortcutTargetW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiGetShortcutTargetWNative, MsiGetShortcutTargetWDart>('MsiGetShortcutTargetW');
// szShortcutPath : LPCWSTR -> Pointer<Utf16>
// szProductCode : LPWSTR optional, out -> Pointer<Utf16>
// szFeatureId : LPWSTR optional, out -> Pointer<Utf16>
// szComponentCode : LPWSTR optional, out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiGetShortcutTargetW"
  c_MsiGetShortcutTargetW :: CWString -> CWString -> CWString -> CWString -> IO Word32
-- szShortcutPath : LPCWSTR -> CWString
-- szProductCode : LPWSTR optional, out -> CWString
-- szFeatureId : LPWSTR optional, out -> CWString
-- szComponentCode : LPWSTR optional, out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msigetshortcuttargetw =
  foreign "MsiGetShortcutTargetW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* szShortcutPath : LPCWSTR -> (ptr uint16_t) *)
(* szProductCode : LPWSTR optional, out -> (ptr uint16_t) *)
(* szFeatureId : LPWSTR optional, out -> (ptr uint16_t) *)
(* szComponentCode : LPWSTR optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiGetShortcutTargetW" msi-get-shortcut-target-w :convention :stdcall) :uint32
  (sz-shortcut-path (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-product-code :pointer)   ; LPWSTR optional, out
  (sz-feature-id :pointer)   ; LPWSTR optional, out
  (sz-component-code :pointer))   ; LPWSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiGetShortcutTargetW = Win32::API::More->new('msi',
    'DWORD MsiGetShortcutTargetW(LPCWSTR szShortcutPath, LPWSTR szProductCode, LPWSTR szFeatureId, LPWSTR szComponentCode)');
# my $ret = $MsiGetShortcutTargetW->Call($szShortcutPath, $szProductCode, $szFeatureId, $szComponentCode);
# szShortcutPath : LPCWSTR -> LPCWSTR
# szProductCode : LPWSTR optional, out -> LPWSTR
# szFeatureId : LPWSTR optional, out -> LPWSTR
# szComponentCode : LPWSTR optional, out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い