ホーム › System.ApplicationInstallationAndServicing › MsiGetProductCodeA
MsiGetProductCodeA
関数コンポーネントから所属製品コードを取得する(ANSI版)。
シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetProductCodeA(
LPCSTR szComponent,
LPSTR lpBuf39
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szComponent | LPCSTR | in | このパラメーターには、アプリケーションによってインストールされたコンポーネントのコンポーネントコードを指定します。通常は、アプリケーションの実行可能ファイルを含むコンポーネントのコンポーネントコードを指定します。 |
| lpBuf39 | LPSTR | out | 製品コードを受け取るバッファーへのポインターです。このバッファーの長さは 39 文字でなければなりません。最初の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetProductCode 関数は、インストール済みまたはアドバタイズされたアプリケーションのコンポーネントのコンポーネントコードを使用して、そのアプリケーションの製品コードを返します。(ANSI)
戻り値
| 値 | 意味 |
|---|---|
| 構成データが破損しています。 | |
| 製品コードを特定できませんでした。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 関数は正常に完了しました。 | |
| 指定されたコンポーネントは不明です。 |
解説(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 (ANSI / -A)
#include <windows.h>
DWORD MsiGetProductCodeA(
LPCSTR szComponent,
LPSTR lpBuf39
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetProductCodeA(
[MarshalAs(UnmanagedType.LPStr)] string szComponent, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuf39 // LPSTR out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetProductCodeA(
<MarshalAs(UnmanagedType.LPStr)> szComponent As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpBuf39 As System.Text.StringBuilder ' LPSTR out
) As UInteger
End Function' szComponent : LPCSTR
' lpBuf39 : LPSTR out
Declare PtrSafe Function MsiGetProductCodeA Lib "msi" ( _
ByVal szComponent As String, _
ByVal lpBuf39 As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetProductCodeA = ctypes.windll.msi.MsiGetProductCodeA
MsiGetProductCodeA.restype = wintypes.DWORD
MsiGetProductCodeA.argtypes = [
wintypes.LPCSTR, # szComponent : LPCSTR
wintypes.LPSTR, # lpBuf39 : LPSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductCodeA = Fiddle::Function.new(
lib['MsiGetProductCodeA'],
[
Fiddle::TYPE_VOIDP, # szComponent : LPCSTR
Fiddle::TYPE_VOIDP, # lpBuf39 : LPSTR out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetProductCodeA(
szComponent: *const u8, // LPCSTR
lpBuf39: *mut u8 // LPSTR out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiGetProductCodeA([MarshalAs(UnmanagedType.LPStr)] string szComponent, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuf39);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductCodeA' -Namespace Win32 -PassThru
# $api::MsiGetProductCodeA(szComponent, lpBuf39)#uselib "msi.dll"
#func global MsiGetProductCodeA "MsiGetProductCodeA" sptr, sptr
; MsiGetProductCodeA szComponent, varptr(lpBuf39) ; 戻り値は stat
; szComponent : LPCSTR -> "sptr"
; lpBuf39 : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetProductCodeA "MsiGetProductCodeA" str, var ; res = MsiGetProductCodeA(szComponent, lpBuf39) ; szComponent : LPCSTR -> "str" ; lpBuf39 : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductCodeA "MsiGetProductCodeA" str, sptr ; res = MsiGetProductCodeA(szComponent, varptr(lpBuf39)) ; szComponent : LPCSTR -> "str" ; lpBuf39 : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetProductCodeA(LPCSTR szComponent, LPSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeA "MsiGetProductCodeA" str, var ; res = MsiGetProductCodeA(szComponent, lpBuf39) ; szComponent : LPCSTR -> "str" ; lpBuf39 : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductCodeA(LPCSTR szComponent, LPSTR lpBuf39) #uselib "msi.dll" #cfunc global MsiGetProductCodeA "MsiGetProductCodeA" str, intptr ; res = MsiGetProductCodeA(szComponent, varptr(lpBuf39)) ; szComponent : LPCSTR -> "str" ; lpBuf39 : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductCodeA = msi.NewProc("MsiGetProductCodeA")
)
// szComponent (LPCSTR), lpBuf39 (LPSTR out)
r1, _, err := procMsiGetProductCodeA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szComponent))),
uintptr(lpBuf39),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductCodeA(
szComponent: PAnsiChar; // LPCSTR
lpBuf39: PAnsiChar // LPSTR out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductCodeA';result := DllCall("msi\MsiGetProductCodeA"
, "AStr", szComponent ; LPCSTR
, "Ptr", lpBuf39 ; LPSTR out
, "UInt") ; return: DWORD●MsiGetProductCodeA(szComponent, lpBuf39) = DLL("msi.dll", "dword MsiGetProductCodeA(char*, char*)")
# 呼び出し: MsiGetProductCodeA(szComponent, lpBuf39)
# szComponent : LPCSTR -> "char*"
# lpBuf39 : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetProductCodeA(
szComponent: [*c]const u8, // LPCSTR
lpBuf39: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetProductCodeA(
szComponent: cstring, # LPCSTR
lpBuf39: ptr char # LPSTR out
): uint32 {.importc: "MsiGetProductCodeA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetProductCodeA(
const(char)* szComponent, // LPCSTR
char* lpBuf39 // LPSTR out
);ccall((:MsiGetProductCodeA, "msi.dll"), stdcall, UInt32,
(Cstring, Ptr{UInt8}),
szComponent, lpBuf39)
# szComponent : LPCSTR -> Cstring
# lpBuf39 : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetProductCodeA(
const char* szComponent,
char* lpBuf39);
]]
local msi = ffi.load("msi")
-- msi.MsiGetProductCodeA(szComponent, lpBuf39)
-- szComponent : LPCSTR
-- lpBuf39 : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetProductCodeA = lib.func('__stdcall', 'MsiGetProductCodeA', 'uint32_t', ['str', 'char *']);
// MsiGetProductCodeA(szComponent, lpBuf39)
// szComponent : LPCSTR -> 'str'
// lpBuf39 : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetProductCodeA: { parameters: ["buffer", "buffer"], result: "u32" },
});
// lib.symbols.MsiGetProductCodeA(szComponent, lpBuf39)
// szComponent : LPCSTR -> "buffer"
// lpBuf39 : LPSTR out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetProductCodeA(
const char* szComponent,
char* lpBuf39);
C, "msi.dll");
// $ffi->MsiGetProductCodeA(szComponent, lpBuf39);
// szComponent : LPCSTR
// lpBuf39 : LPSTR 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 MsiGetProductCodeA(
String szComponent, // LPCSTR
byte[] lpBuf39 // LPSTR out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetProductCodeA = MsiGetProductCodeA(
szComponent : UInt8*, # LPCSTR
lpBuf39 : UInt8* # LPSTR out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetProductCodeANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef MsiGetProductCodeADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final MsiGetProductCodeA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetProductCodeANative, MsiGetProductCodeADart>('MsiGetProductCodeA');
// szComponent : LPCSTR -> Pointer<Utf8>
// lpBuf39 : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetProductCodeA(
szComponent: PAnsiChar; // LPCSTR
lpBuf39: PAnsiChar // LPSTR out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductCodeA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetProductCodeA"
c_MsiGetProductCodeA :: CString -> CString -> IO Word32
-- szComponent : LPCSTR -> CString
-- lpBuf39 : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetproductcodea =
foreign "MsiGetProductCodeA"
(string @-> string @-> returning uint32_t)
(* szComponent : LPCSTR -> string *)
(* lpBuf39 : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetProductCodeA" msi-get-product-code-a :convention :stdcall) :uint32
(sz-component :string) ; LPCSTR
(lp-buf39 :pointer)) ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetProductCodeA = Win32::API::More->new('msi',
'DWORD MsiGetProductCodeA(LPCSTR szComponent, LPSTR lpBuf39)');
# my $ret = $MsiGetProductCodeA->Call($szComponent, $lpBuf39);
# szComponent : LPCSTR -> LPCSTR
# lpBuf39 : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f MsiGetProductCodeW (Unicode版) — コンポーネントから所属製品コードを取得する(Unicode版)。