ホーム › System.ApplicationInstallationAndServicing › MsiGetShortcutTargetA
MsiGetShortcutTargetA
関数ショートカットから製品、フィーチャー、コンポーネントの情報を取得する。
シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetShortcutTargetA(
LPCSTR szShortcutPath,
LPSTR szProductCode, // optional
LPSTR szFeatureId, // optional
LPSTR szComponentCode // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szShortcutPath | LPCSTR | in | ショートカットへのフルパスを指定する、null で終わる文字列。 |
| szProductCode | LPSTR | outoptional | ショートカットの製品コードを表す GUID。この文字列バッファは 39 文字分の長さが必要です。先頭の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。このパラメーターには null を指定できます。 |
| szFeatureId | LPSTR | outoptional | ショートカットの機能名。文字列バッファは MAX_FEATURE_CHARS+1 文字分の長さが必要です。このパラメーターには null を指定できます。 |
| szComponentCode | LPSTR | outoptional | コンポーネントコードを表す GUID。この文字列バッファは 39 文字分の長さが必要です。先頭の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。このパラメーターには null を指定できます。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetShortcutTarget 関数はショートカットを調べ、可能であればその製品、機能名、コンポーネントを返します。(ANSI)
戻り値
この関数は UINT を返します。
解説(Remarks)
関数が失敗し、かつショートカットが存在する場合、ショートカットの通常の内容には IShellLink インターフェイスを通じてアクセスできます。
それ以外の場合、ターゲットの状態は インストーラー選択関数 を使用して判別できます。
メモ
msi.h ヘッダーは MsiGetShortcutTarget を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、関数プロトタイプの規則 を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetShortcutTargetA(
LPCSTR szShortcutPath,
LPSTR szProductCode, // optional
LPSTR szFeatureId, // optional
LPSTR szComponentCode // optional
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetShortcutTargetA(
[MarshalAs(UnmanagedType.LPStr)] string szShortcutPath, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szProductCode, // LPSTR optional, out
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szFeatureId, // LPSTR optional, out
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szComponentCode // LPSTR optional, out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetShortcutTargetA(
<MarshalAs(UnmanagedType.LPStr)> szShortcutPath As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szProductCode As System.Text.StringBuilder, ' LPSTR optional, out
<MarshalAs(UnmanagedType.LPStr)> szFeatureId As System.Text.StringBuilder, ' LPSTR optional, out
<MarshalAs(UnmanagedType.LPStr)> szComponentCode As System.Text.StringBuilder ' LPSTR optional, out
) As UInteger
End Function' szShortcutPath : LPCSTR
' szProductCode : LPSTR optional, out
' szFeatureId : LPSTR optional, out
' szComponentCode : LPSTR optional, out
Declare PtrSafe Function MsiGetShortcutTargetA Lib "msi" ( _
ByVal szShortcutPath As String, _
ByVal szProductCode As String, _
ByVal szFeatureId As String, _
ByVal szComponentCode As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetShortcutTargetA = ctypes.windll.msi.MsiGetShortcutTargetA
MsiGetShortcutTargetA.restype = wintypes.DWORD
MsiGetShortcutTargetA.argtypes = [
wintypes.LPCSTR, # szShortcutPath : LPCSTR
wintypes.LPSTR, # szProductCode : LPSTR optional, out
wintypes.LPSTR, # szFeatureId : LPSTR optional, out
wintypes.LPSTR, # szComponentCode : LPSTR optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetShortcutTargetA = Fiddle::Function.new(
lib['MsiGetShortcutTargetA'],
[
Fiddle::TYPE_VOIDP, # szShortcutPath : LPCSTR
Fiddle::TYPE_VOIDP, # szProductCode : LPSTR optional, out
Fiddle::TYPE_VOIDP, # szFeatureId : LPSTR optional, out
Fiddle::TYPE_VOIDP, # szComponentCode : LPSTR optional, out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetShortcutTargetA(
szShortcutPath: *const u8, // LPCSTR
szProductCode: *mut u8, // LPSTR optional, out
szFeatureId: *mut u8, // LPSTR optional, out
szComponentCode: *mut u8 // LPSTR optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiGetShortcutTargetA([MarshalAs(UnmanagedType.LPStr)] string szShortcutPath, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szProductCode, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szFeatureId, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder szComponentCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetShortcutTargetA' -Namespace Win32 -PassThru
# $api::MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode)#uselib "msi.dll"
#func global MsiGetShortcutTargetA "MsiGetShortcutTargetA" sptr, sptr, sptr, sptr
; MsiGetShortcutTargetA szShortcutPath, varptr(szProductCode), varptr(szFeatureId), varptr(szComponentCode) ; 戻り値は stat
; szShortcutPath : LPCSTR -> "sptr"
; szProductCode : LPSTR optional, out -> "sptr"
; szFeatureId : LPSTR optional, out -> "sptr"
; szComponentCode : LPSTR optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetShortcutTargetA "MsiGetShortcutTargetA" str, var, var, var ; res = MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode) ; szShortcutPath : LPCSTR -> "str" ; szProductCode : LPSTR optional, out -> "var" ; szFeatureId : LPSTR optional, out -> "var" ; szComponentCode : LPSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetShortcutTargetA "MsiGetShortcutTargetA" str, sptr, sptr, sptr ; res = MsiGetShortcutTargetA(szShortcutPath, varptr(szProductCode), varptr(szFeatureId), varptr(szComponentCode)) ; szShortcutPath : LPCSTR -> "str" ; szProductCode : LPSTR optional, out -> "sptr" ; szFeatureId : LPSTR optional, out -> "sptr" ; szComponentCode : LPSTR optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetShortcutTargetA(LPCSTR szShortcutPath, LPSTR szProductCode, LPSTR szFeatureId, LPSTR szComponentCode) #uselib "msi.dll" #cfunc global MsiGetShortcutTargetA "MsiGetShortcutTargetA" str, var, var, var ; res = MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode) ; szShortcutPath : LPCSTR -> "str" ; szProductCode : LPSTR optional, out -> "var" ; szFeatureId : LPSTR optional, out -> "var" ; szComponentCode : LPSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetShortcutTargetA(LPCSTR szShortcutPath, LPSTR szProductCode, LPSTR szFeatureId, LPSTR szComponentCode) #uselib "msi.dll" #cfunc global MsiGetShortcutTargetA "MsiGetShortcutTargetA" str, intptr, intptr, intptr ; res = MsiGetShortcutTargetA(szShortcutPath, varptr(szProductCode), varptr(szFeatureId), varptr(szComponentCode)) ; szShortcutPath : LPCSTR -> "str" ; szProductCode : LPSTR optional, out -> "intptr" ; szFeatureId : LPSTR optional, out -> "intptr" ; szComponentCode : LPSTR optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetShortcutTargetA = msi.NewProc("MsiGetShortcutTargetA")
)
// szShortcutPath (LPCSTR), szProductCode (LPSTR optional, out), szFeatureId (LPSTR optional, out), szComponentCode (LPSTR optional, out)
r1, _, err := procMsiGetShortcutTargetA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szShortcutPath))),
uintptr(szProductCode),
uintptr(szFeatureId),
uintptr(szComponentCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetShortcutTargetA(
szShortcutPath: PAnsiChar; // LPCSTR
szProductCode: PAnsiChar; // LPSTR optional, out
szFeatureId: PAnsiChar; // LPSTR optional, out
szComponentCode: PAnsiChar // LPSTR optional, out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetShortcutTargetA';result := DllCall("msi\MsiGetShortcutTargetA"
, "AStr", szShortcutPath ; LPCSTR
, "Ptr", szProductCode ; LPSTR optional, out
, "Ptr", szFeatureId ; LPSTR optional, out
, "Ptr", szComponentCode ; LPSTR optional, out
, "UInt") ; return: DWORD●MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode) = DLL("msi.dll", "dword MsiGetShortcutTargetA(char*, char*, char*, char*)")
# 呼び出し: MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
# szShortcutPath : LPCSTR -> "char*"
# szProductCode : LPSTR optional, out -> "char*"
# szFeatureId : LPSTR optional, out -> "char*"
# szComponentCode : LPSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetShortcutTargetA(
szShortcutPath: [*c]const u8, // LPCSTR
szProductCode: [*c]u8, // LPSTR optional, out
szFeatureId: [*c]u8, // LPSTR optional, out
szComponentCode: [*c]u8 // LPSTR optional, out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetShortcutTargetA(
szShortcutPath: cstring, # LPCSTR
szProductCode: ptr char, # LPSTR optional, out
szFeatureId: ptr char, # LPSTR optional, out
szComponentCode: ptr char # LPSTR optional, out
): uint32 {.importc: "MsiGetShortcutTargetA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetShortcutTargetA(
const(char)* szShortcutPath, // LPCSTR
char* szProductCode, // LPSTR optional, out
char* szFeatureId, // LPSTR optional, out
char* szComponentCode // LPSTR optional, out
);ccall((:MsiGetShortcutTargetA, "msi.dll"), stdcall, UInt32,
(Cstring, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}),
szShortcutPath, szProductCode, szFeatureId, szComponentCode)
# szShortcutPath : LPCSTR -> Cstring
# szProductCode : LPSTR optional, out -> Ptr{UInt8}
# szFeatureId : LPSTR optional, out -> Ptr{UInt8}
# szComponentCode : LPSTR optional, out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetShortcutTargetA(
const char* szShortcutPath,
char* szProductCode,
char* szFeatureId,
char* szComponentCode);
]]
local msi = ffi.load("msi")
-- msi.MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
-- szShortcutPath : LPCSTR
-- szProductCode : LPSTR optional, out
-- szFeatureId : LPSTR optional, out
-- szComponentCode : LPSTR optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetShortcutTargetA = lib.func('__stdcall', 'MsiGetShortcutTargetA', 'uint32_t', ['str', 'char *', 'char *', 'char *']);
// MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
// szShortcutPath : LPCSTR -> 'str'
// szProductCode : LPSTR optional, out -> 'char *'
// szFeatureId : LPSTR optional, out -> 'char *'
// szComponentCode : LPSTR optional, out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetShortcutTargetA: { parameters: ["buffer", "buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode)
// szShortcutPath : LPCSTR -> "buffer"
// szProductCode : LPSTR optional, out -> "buffer"
// szFeatureId : LPSTR optional, out -> "buffer"
// szComponentCode : LPSTR optional, out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetShortcutTargetA(
const char* szShortcutPath,
char* szProductCode,
char* szFeatureId,
char* szComponentCode);
C, "msi.dll");
// $ffi->MsiGetShortcutTargetA(szShortcutPath, szProductCode, szFeatureId, szComponentCode);
// szShortcutPath : LPCSTR
// szProductCode : LPSTR optional, out
// szFeatureId : LPSTR optional, out
// szComponentCode : LPSTR 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.ASCII_OPTIONS);
int MsiGetShortcutTargetA(
String szShortcutPath, // LPCSTR
byte[] szProductCode, // LPSTR optional, out
byte[] szFeatureId, // LPSTR optional, out
byte[] szComponentCode // LPSTR optional, out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetShortcutTargetA = MsiGetShortcutTargetA(
szShortcutPath : UInt8*, # LPCSTR
szProductCode : UInt8*, # LPSTR optional, out
szFeatureId : UInt8*, # LPSTR optional, out
szComponentCode : UInt8* # LPSTR 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 MsiGetShortcutTargetANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
typedef MsiGetShortcutTargetADart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
final MsiGetShortcutTargetA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetShortcutTargetANative, MsiGetShortcutTargetADart>('MsiGetShortcutTargetA');
// szShortcutPath : LPCSTR -> Pointer<Utf8>
// szProductCode : LPSTR optional, out -> Pointer<Utf8>
// szFeatureId : LPSTR optional, out -> Pointer<Utf8>
// szComponentCode : LPSTR optional, out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetShortcutTargetA(
szShortcutPath: PAnsiChar; // LPCSTR
szProductCode: PAnsiChar; // LPSTR optional, out
szFeatureId: PAnsiChar; // LPSTR optional, out
szComponentCode: PAnsiChar // LPSTR optional, out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetShortcutTargetA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetShortcutTargetA"
c_MsiGetShortcutTargetA :: CString -> CString -> CString -> CString -> IO Word32
-- szShortcutPath : LPCSTR -> CString
-- szProductCode : LPSTR optional, out -> CString
-- szFeatureId : LPSTR optional, out -> CString
-- szComponentCode : LPSTR optional, out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetshortcuttargeta =
foreign "MsiGetShortcutTargetA"
(string @-> string @-> string @-> string @-> returning uint32_t)
(* szShortcutPath : LPCSTR -> string *)
(* szProductCode : LPSTR optional, out -> string *)
(* szFeatureId : LPSTR optional, out -> string *)
(* szComponentCode : LPSTR optional, out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetShortcutTargetA" msi-get-shortcut-target-a :convention :stdcall) :uint32
(sz-shortcut-path :string) ; LPCSTR
(sz-product-code :pointer) ; LPSTR optional, out
(sz-feature-id :pointer) ; LPSTR optional, out
(sz-component-code :pointer)) ; LPSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetShortcutTargetA = Win32::API::More->new('msi',
'DWORD MsiGetShortcutTargetA(LPCSTR szShortcutPath, LPSTR szProductCode, LPSTR szFeatureId, LPSTR szComponentCode)');
# my $ret = $MsiGetShortcutTargetA->Call($szShortcutPath, $szProductCode, $szFeatureId, $szComponentCode);
# szShortcutPath : LPCSTR -> LPCSTR
# szProductCode : LPSTR optional, out -> LPSTR
# szFeatureId : LPSTR optional, out -> LPSTR
# szComponentCode : LPSTR optional, out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f MsiGetShortcutTargetW (Unicode版) — ショートカットから製品、フィーチャー、コンポーネントの情報を取得する。