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

MsiAdvertiseProductW

関数
製品をシステムにアドバタイズ(広告登録)する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiAdvertiseProductW(
    LPCWSTR szPackagePath,
    LPCWSTR szScriptfilePath,   // optional
    LPCWSTR szTransforms,   // optional
    WORD lgidLanguage
);

パラメーター

名前方向説明
szPackagePathLPCWSTRinアドバタイズする製品のパッケージへのフルパス。
szScriptfilePathLPCWSTRinoptional

アドバタイズ情報を格納して作成されるスクリプトファイルへのフルパス。製品をローカルのコンピューターにアドバタイズするには、ADVERTISEFLAGS_MACHINEASSIGN または ADVERTISEFLAGS_USERASSIGN を設定します。

フラグ 意味
ADVERTISEFLAGS_MACHINEASSIGN
0
すべてのユーザーが利用できる、製品のコンピューター単位のインストールをアドバタイズする場合に設定します。
ADVERTISEFLAGS_USERASSIGN
1
特定のユーザーが利用できる、製品のユーザー単位のインストールをアドバタイズする場合に設定します。
szTransformsLPCWSTRinoptional適用するトランスフォームのセミコロン区切りのリスト。トランスフォームのリストには、トランスフォームのセキュアキャッシュを指定するために @ または | の文字をプレフィックスとして付加できます。@ プレフィックスは secure-at-source トランスフォームを指定し、| プレフィックスは secure full path トランスフォームを示します。詳細については、 Secured Transforms を参照してください。このパラメーターは null でもかまいません。
lgidLanguageWORDinソースが複数の言語をサポートしている場合に使用するインストール言語。

戻り値の型: DWORD

公式ドキュメント

MsiAdvertiseProduct 関数は、アドバタイズスクリプトを生成するか、製品をコンピューターにアドバタイズします。(Unicode)

戻り値

意味
ERROR_SUCCESS
関数が正常に完了しました。
アクションに関連するエラー
Error Codes を参照してください。
Initialization Error
初期化エラーが発生しました。
ERROR_CALL_NOT_IMPLEMENTED
Windows 2000 または Windows XP 以外のプラットフォームでアドバタイズスクリプトを生成しようとすると、このエラーが返されます。ローカルコンピューターへのアドバタイズは、すべてのプラットフォームでサポートされています。

解説(Remarks)

メモ

msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiAdvertiseProduct を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、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 MsiAdvertiseProductW(
    LPCWSTR szPackagePath,
    LPCWSTR szScriptfilePath,   // optional
    LPCWSTR szTransforms,   // optional
    WORD lgidLanguage
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiAdvertiseProductW(
    [MarshalAs(UnmanagedType.LPWStr)] string szPackagePath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szScriptfilePath,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string szTransforms,   // LPCWSTR optional
    ushort lgidLanguage   // WORD
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiAdvertiseProductW(
    <MarshalAs(UnmanagedType.LPWStr)> szPackagePath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szScriptfilePath As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> szTransforms As String,   ' LPCWSTR optional
    lgidLanguage As UShort   ' WORD
) As UInteger
End Function
' szPackagePath : LPCWSTR
' szScriptfilePath : LPCWSTR optional
' szTransforms : LPCWSTR optional
' lgidLanguage : WORD
Declare PtrSafe Function MsiAdvertiseProductW Lib "msi" ( _
    ByVal szPackagePath As LongPtr, _
    ByVal szScriptfilePath As LongPtr, _
    ByVal szTransforms As LongPtr, _
    ByVal lgidLanguage As Integer) 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

MsiAdvertiseProductW = ctypes.windll.msi.MsiAdvertiseProductW
MsiAdvertiseProductW.restype = wintypes.DWORD
MsiAdvertiseProductW.argtypes = [
    wintypes.LPCWSTR,  # szPackagePath : LPCWSTR
    wintypes.LPCWSTR,  # szScriptfilePath : LPCWSTR optional
    wintypes.LPCWSTR,  # szTransforms : LPCWSTR optional
    ctypes.c_ushort,  # lgidLanguage : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiAdvertiseProductW = Fiddle::Function.new(
  lib['MsiAdvertiseProductW'],
  [
    Fiddle::TYPE_VOIDP,  # szPackagePath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szScriptfilePath : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # szTransforms : LPCWSTR optional
    -Fiddle::TYPE_SHORT,  # lgidLanguage : WORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiAdvertiseProductW(
        szPackagePath: *const u16,  // LPCWSTR
        szScriptfilePath: *const u16,  // LPCWSTR optional
        szTransforms: *const u16,  // LPCWSTR optional
        lgidLanguage: u16  // WORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiAdvertiseProductW([MarshalAs(UnmanagedType.LPWStr)] string szPackagePath, [MarshalAs(UnmanagedType.LPWStr)] string szScriptfilePath, [MarshalAs(UnmanagedType.LPWStr)] string szTransforms, ushort lgidLanguage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiAdvertiseProductW' -Namespace Win32 -PassThru
# $api::MsiAdvertiseProductW(szPackagePath, szScriptfilePath, szTransforms, lgidLanguage)
#uselib "msi.dll"
#func global MsiAdvertiseProductW "MsiAdvertiseProductW" wptr, wptr, wptr, wptr
; MsiAdvertiseProductW szPackagePath, szScriptfilePath, szTransforms, lgidLanguage   ; 戻り値は stat
; szPackagePath : LPCWSTR -> "wptr"
; szScriptfilePath : LPCWSTR optional -> "wptr"
; szTransforms : LPCWSTR optional -> "wptr"
; lgidLanguage : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiAdvertiseProductW "MsiAdvertiseProductW" wstr, wstr, wstr, int
; res = MsiAdvertiseProductW(szPackagePath, szScriptfilePath, szTransforms, lgidLanguage)
; szPackagePath : LPCWSTR -> "wstr"
; szScriptfilePath : LPCWSTR optional -> "wstr"
; szTransforms : LPCWSTR optional -> "wstr"
; lgidLanguage : WORD -> "int"
; DWORD MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath, LPCWSTR szTransforms, WORD lgidLanguage)
#uselib "msi.dll"
#cfunc global MsiAdvertiseProductW "MsiAdvertiseProductW" wstr, wstr, wstr, int
; res = MsiAdvertiseProductW(szPackagePath, szScriptfilePath, szTransforms, lgidLanguage)
; szPackagePath : LPCWSTR -> "wstr"
; szScriptfilePath : LPCWSTR optional -> "wstr"
; szTransforms : LPCWSTR optional -> "wstr"
; lgidLanguage : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiAdvertiseProductW = msi.NewProc("MsiAdvertiseProductW")
)

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

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

typedef MsiAdvertiseProductWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint16);
typedef MsiAdvertiseProductWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int);
final MsiAdvertiseProductW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiAdvertiseProductWNative, MsiAdvertiseProductWDart>('MsiAdvertiseProductW');
// szPackagePath : LPCWSTR -> Pointer<Utf16>
// szScriptfilePath : LPCWSTR optional -> Pointer<Utf16>
// szTransforms : LPCWSTR optional -> Pointer<Utf16>
// lgidLanguage : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiAdvertiseProductW(
  szPackagePath: PWideChar;   // LPCWSTR
  szScriptfilePath: PWideChar;   // LPCWSTR optional
  szTransforms: PWideChar;   // LPCWSTR optional
  lgidLanguage: Word   // WORD
): DWORD; stdcall;
  external 'msi.dll' name 'MsiAdvertiseProductW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiAdvertiseProductW"
  c_MsiAdvertiseProductW :: CWString -> CWString -> CWString -> Word16 -> IO Word32
-- szPackagePath : LPCWSTR -> CWString
-- szScriptfilePath : LPCWSTR optional -> CWString
-- szTransforms : LPCWSTR optional -> CWString
-- lgidLanguage : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msiadvertiseproductw =
  foreign "MsiAdvertiseProductW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint16_t @-> returning uint32_t)
(* szPackagePath : LPCWSTR -> (ptr uint16_t) *)
(* szScriptfilePath : LPCWSTR optional -> (ptr uint16_t) *)
(* szTransforms : LPCWSTR optional -> (ptr uint16_t) *)
(* lgidLanguage : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiAdvertiseProductW" msi-advertise-product-w :convention :stdcall) :uint32
  (sz-package-path (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-scriptfile-path (:string :encoding :utf-16le))   ; LPCWSTR optional
  (sz-transforms (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lgid-language :uint16))   ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiAdvertiseProductW = Win32::API::More->new('msi',
    'DWORD MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath, LPCWSTR szTransforms, WORD lgidLanguage)');
# my $ret = $MsiAdvertiseProductW->Call($szPackagePath, $szScriptfilePath, $szTransforms, $lgidLanguage);
# szPackagePath : LPCWSTR -> LPCWSTR
# szScriptfilePath : LPCWSTR optional -> LPCWSTR
# szTransforms : LPCWSTR optional -> LPCWSTR
# lgidLanguage : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
類似 API