ホーム › System.ApplicationInstallationAndServicing › MsiGetProductCodeW
MsiGetProductCodeW
関数コンポーネントから所属製品コードを取得する(Unicode版)。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductCodeW(
LPCWSTR szComponent,
LPWSTR lpBuf39
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szComponent | LPCWSTR | in | このパラメーターには、アプリケーションによってインストールされたコンポーネントのコンポーネントコードを指定します。通常は、アプリケーションの実行可能ファイルを含むコンポーネントのコンポーネントコードを指定します。 |
| lpBuf39 | LPWSTR | out | プロダクトコードを受け取るバッファーへのポインター。このバッファーの長さは 39 文字でなければなりません。最初の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetProductCode 関数は、アプリケーションのインストール済みまたはアドバタイズ済みコンポーネントのコンポーネントコードを使用して、そのアプリケーションのプロダクトコードを返します。(Unicode)
戻り値
| Value | Meaning |
|---|---|
| 構成データが破損しています。 | |
| プロダクトコードを特定できませんでした。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 関数は正常に完了しました。 | |
| 指定されたコンポーネントは不明です。 |
解説(Remarks)
初期化の際、アプリケーションは自身がどのプロダクトコードでインストールされたかを特定する必要があります。アプリケーションは、インストールごとに異なる製品の一部となることがあります。たとえば、アプリケーションは複数のアプリケーションから成るスイートの一部である場合もあれば、単独でインストールされる場合もあります。
メモ
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetProductCode を定義します。エンコーディング中立なエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductCodeW(
LPCWSTR szComponent,
LPWSTR lpBuf39
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetProductCodeW(
[MarshalAs(UnmanagedType.LPWStr)] string szComponent, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuf39 // LPWSTR out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetProductCodeW(
<MarshalAs(UnmanagedType.LPWStr)> szComponent As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpBuf39 As System.Text.StringBuilder ' LPWSTR out
) As UInteger
End Function' szComponent : LPCWSTR
' lpBuf39 : LPWSTR out
Declare PtrSafe Function MsiGetProductCodeW Lib "msi" ( _
ByVal szComponent As LongPtr, _
ByVal lpBuf39 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
MsiGetProductCodeW = ctypes.windll.msi.MsiGetProductCodeW
MsiGetProductCodeW.restype = wintypes.DWORD
MsiGetProductCodeW.argtypes = [
wintypes.LPCWSTR, # szComponent : LPCWSTR
wintypes.LPWSTR, # lpBuf39 : LPWSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductCodeW = Fiddle::Function.new(
lib['MsiGetProductCodeW'],
[
Fiddle::TYPE_VOIDP, # szComponent : LPCWSTR
Fiddle::TYPE_VOIDP, # lpBuf39 : LPWSTR out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetProductCodeW(
szComponent: *const u16, // LPCWSTR
lpBuf39: *mut u16 // LPWSTR out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetProductCodeW([MarshalAs(UnmanagedType.LPWStr)] string szComponent, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuf39);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductCodeW' -Namespace Win32 -PassThru
# $api::MsiGetProductCodeW(szComponent, lpBuf39)#uselib "msi.dll"
#func global MsiGetProductCodeW "MsiGetProductCodeW" wptr, wptr
; MsiGetProductCodeW szComponent, varptr(lpBuf39) ; 戻り値は stat
; szComponent : LPCWSTR -> "wptr"
; lpBuf39 : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, var ; res = MsiGetProductCodeW(szComponent, lpBuf39) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, sptr ; res = MsiGetProductCodeW(szComponent, varptr(lpBuf39)) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, var ; res = MsiGetProductCodeW(szComponent, lpBuf39) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeW "MsiGetProductCodeW" wstr, intptr ; res = MsiGetProductCodeW(szComponent, varptr(lpBuf39)) ; szComponent : LPCWSTR -> "wstr" ; lpBuf39 : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductCodeW = msi.NewProc("MsiGetProductCodeW")
)
// szComponent (LPCWSTR), lpBuf39 (LPWSTR out)
r1, _, err := procMsiGetProductCodeW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
uintptr(lpBuf39),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductCodeW(
szComponent: PWideChar; // LPCWSTR
lpBuf39: PWideChar // LPWSTR out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductCodeW';result := DllCall("msi\MsiGetProductCodeW"
, "WStr", szComponent ; LPCWSTR
, "Ptr", lpBuf39 ; LPWSTR out
, "UInt") ; return: DWORD●MsiGetProductCodeW(szComponent, lpBuf39) = DLL("msi.dll", "dword MsiGetProductCodeW(char*, char*)")
# 呼び出し: MsiGetProductCodeW(szComponent, lpBuf39)
# szComponent : LPCWSTR -> "char*"
# lpBuf39 : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetProductCodeW(
szComponent: [*c]const u16, // LPCWSTR
lpBuf39: [*c]u16 // LPWSTR out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetProductCodeW(
szComponent: WideCString, # LPCWSTR
lpBuf39: ptr uint16 # LPWSTR out
): uint32 {.importc: "MsiGetProductCodeW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetProductCodeW(
const(wchar)* szComponent, // LPCWSTR
wchar* lpBuf39 // LPWSTR out
);ccall((:MsiGetProductCodeW, "msi.dll"), stdcall, UInt32,
(Cwstring, Ptr{UInt16}),
szComponent, lpBuf39)
# szComponent : LPCWSTR -> Cwstring
# lpBuf39 : LPWSTR out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetProductCodeW(
const uint16_t* szComponent,
uint16_t* lpBuf39);
]]
local msi = ffi.load("msi")
-- msi.MsiGetProductCodeW(szComponent, lpBuf39)
-- szComponent : LPCWSTR
-- lpBuf39 : LPWSTR 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 MsiGetProductCodeW = lib.func('__stdcall', 'MsiGetProductCodeW', 'uint32_t', ['str16', 'uint16_t *']);
// MsiGetProductCodeW(szComponent, lpBuf39)
// szComponent : LPCWSTR -> 'str16'
// lpBuf39 : LPWSTR out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetProductCodeW: { parameters: ["buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiGetProductCodeW(szComponent, lpBuf39)
// szComponent : LPCWSTR -> "buffer"
// lpBuf39 : LPWSTR out -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetProductCodeW(
const uint16_t* szComponent,
uint16_t* lpBuf39);
C, "msi.dll");
// $ffi->MsiGetProductCodeW(szComponent, lpBuf39);
// szComponent : LPCWSTR
// lpBuf39 : LPWSTR 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 MsiGetProductCodeW(
WString szComponent, // LPCWSTR
char[] lpBuf39 // LPWSTR out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetProductCodeW = MsiGetProductCodeW(
szComponent : UInt16*, # LPCWSTR
lpBuf39 : UInt16* # LPWSTR out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetProductCodeWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef MsiGetProductCodeWDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final MsiGetProductCodeW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetProductCodeWNative, MsiGetProductCodeWDart>('MsiGetProductCodeW');
// szComponent : LPCWSTR -> Pointer<Utf16>
// lpBuf39 : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetProductCodeW(
szComponent: PWideChar; // LPCWSTR
lpBuf39: PWideChar // LPWSTR out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductCodeW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetProductCodeW"
c_MsiGetProductCodeW :: CWString -> CWString -> IO Word32
-- szComponent : LPCWSTR -> CWString
-- lpBuf39 : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetproductcodew =
foreign "MsiGetProductCodeW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* lpBuf39 : LPWSTR 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 ("MsiGetProductCodeW" msi-get-product-code-w :convention :stdcall) :uint32
(sz-component (:string :encoding :utf-16le)) ; LPCWSTR
(lp-buf39 :pointer)) ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetProductCodeW = Win32::API::More->new('msi',
'DWORD MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR lpBuf39)');
# my $ret = $MsiGetProductCodeW->Call($szComponent, $lpBuf39);
# szComponent : LPCWSTR -> LPCWSTR
# lpBuf39 : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f MsiGetProductCodeA (ANSI版) — コンポーネントから所属製品コードを取得する(ANSI版)。