ホーム › System.ApplicationInstallationAndServicing › MsiGetUserInfoW
MsiGetUserInfoW
関数製品に登録されたユーザー情報を取得する(Unicode版)。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
USERINFOSTATE MsiGetUserInfoW(
LPCWSTR szProduct,
LPWSTR lpUserNameBuf, // optional
DWORD* pcchUserNameBuf, // optional
LPWSTR lpOrgNameBuf, // optional
DWORD* pcchOrgNameBuf, // optional
LPWSTR lpSerialBuf, // optional
DWORD* pcchSerialBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szProduct | LPCWSTR | in | クエリ対象となる製品の製品コードを指定します。 |
| lpUserNameBuf | LPWSTR | outoptional | ユーザー名を受け取る変数へのポインターです。 |
| pcchUserNameBuf | DWORD* | inoutoptional | lpUserNameBuf パラメーターが指すバッファーのサイズを文字数で指定する変数へのポインターです。このサイズには終端の null 文字分を含める必要があります。 |
| lpOrgNameBuf | LPWSTR | outoptional | 組織名を受け取るバッファーへのポインターです。 |
| pcchOrgNameBuf | DWORD* | inoutoptional | lpOrgNameBuf パラメーターが指すバッファーのサイズを文字数で指定する変数へのポインターです。入力時には、終端の null 文字分のスペースを含むバッファーの全サイズを指定します。渡されたバッファーが小さすぎる場合、返される文字数には終端の null 文字は含まれません。 |
| lpSerialBuf | LPWSTR | outoptional | 製品 ID を受け取るバッファーへのポインターです。 |
| pcchSerialBuf | DWORD* | inoutoptional | lpSerialBuf パラメーターが指すバッファーのサイズを文字数で指定する変数へのポインターです。入力時には、終端の null 文字分のスペースを含むバッファーの全サイズを指定します。渡されたバッファーが小さすぎる場合、返される文字数には終端の null 文字は含まれません。 |
戻り値の型: USERINFOSTATE
公式ドキュメント
MsiGetUserInfo 関数は、インストール済み製品の登録ユーザー情報を返します。(Unicode)
戻り値
| 値 | 意味 |
|---|---|
| ユーザー情報の一部またはすべてが存在しません。 | |
| 関数パラメーターのいずれかが無効でした。 | |
| バッファーが小さすぎて、要求されたデータを保持できません。 | |
| 関数は正常に完了しました。 | |
| 製品コードが既知の製品を識別しません。 |
解説(Remarks)
MsiGetUserInfo 関数が戻るとき、pcchNameBuf パラメーターにはバッファーに格納されたクラス文字列の長さが格納されます。返される文字数には終端の null 文字は含まれません。バッファーが十分な大きさでない場合、MsiGetUserInfo 関数は USERINFOSTATE_MOREDATA を返し、MsiGetUserInfo には null 文字を数えない文字数単位の文字列のサイズが格納されます。
会社名が存在しない場合でも、ユーザー情報は存在するものとみなされます。
メモ
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetUserInfo を定義します。エンコーディングに依存しないエイリアスの使用を、エンコーディングに依存しないコードでない部分と混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
USERINFOSTATE MsiGetUserInfoW(
LPCWSTR szProduct,
LPWSTR lpUserNameBuf, // optional
DWORD* pcchUserNameBuf, // optional
LPWSTR lpOrgNameBuf, // optional
DWORD* pcchOrgNameBuf, // optional
LPWSTR lpSerialBuf, // optional
DWORD* pcchSerialBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiGetUserInfoW(
[MarshalAs(UnmanagedType.LPWStr)] string szProduct, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpUserNameBuf, // LPWSTR optional, out
IntPtr pcchUserNameBuf, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpOrgNameBuf, // LPWSTR optional, out
IntPtr pcchOrgNameBuf, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpSerialBuf, // LPWSTR optional, out
IntPtr pcchSerialBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetUserInfoW(
<MarshalAs(UnmanagedType.LPWStr)> szProduct As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpUserNameBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchUserNameBuf As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> lpOrgNameBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchOrgNameBuf As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> lpSerialBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchSerialBuf As IntPtr ' DWORD* optional, in/out
) As Integer
End Function' szProduct : LPCWSTR
' lpUserNameBuf : LPWSTR optional, out
' pcchUserNameBuf : DWORD* optional, in/out
' lpOrgNameBuf : LPWSTR optional, out
' pcchOrgNameBuf : DWORD* optional, in/out
' lpSerialBuf : LPWSTR optional, out
' pcchSerialBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetUserInfoW Lib "msi" ( _
ByVal szProduct As LongPtr, _
ByVal lpUserNameBuf As LongPtr, _
ByVal pcchUserNameBuf As LongPtr, _
ByVal lpOrgNameBuf As LongPtr, _
ByVal pcchOrgNameBuf As LongPtr, _
ByVal lpSerialBuf As LongPtr, _
ByVal pcchSerialBuf 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
MsiGetUserInfoW = ctypes.windll.msi.MsiGetUserInfoW
MsiGetUserInfoW.restype = ctypes.c_int
MsiGetUserInfoW.argtypes = [
wintypes.LPCWSTR, # szProduct : LPCWSTR
wintypes.LPWSTR, # lpUserNameBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchUserNameBuf : DWORD* optional, in/out
wintypes.LPWSTR, # lpOrgNameBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchOrgNameBuf : DWORD* optional, in/out
wintypes.LPWSTR, # lpSerialBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchSerialBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetUserInfoW = Fiddle::Function.new(
lib['MsiGetUserInfoW'],
[
Fiddle::TYPE_VOIDP, # szProduct : LPCWSTR
Fiddle::TYPE_VOIDP, # lpUserNameBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchUserNameBuf : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # lpOrgNameBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchOrgNameBuf : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # lpSerialBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchSerialBuf : DWORD* optional, in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetUserInfoW(
szProduct: *const u16, // LPCWSTR
lpUserNameBuf: *mut u16, // LPWSTR optional, out
pcchUserNameBuf: *mut u32, // DWORD* optional, in/out
lpOrgNameBuf: *mut u16, // LPWSTR optional, out
pcchOrgNameBuf: *mut u32, // DWORD* optional, in/out
lpSerialBuf: *mut u16, // LPWSTR optional, out
pcchSerialBuf: *mut u32 // DWORD* optional, in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiGetUserInfoW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpUserNameBuf, IntPtr pcchUserNameBuf, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpOrgNameBuf, IntPtr pcchOrgNameBuf, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpSerialBuf, IntPtr pcchSerialBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetUserInfoW' -Namespace Win32 -PassThru
# $api::MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)#uselib "msi.dll"
#func global MsiGetUserInfoW "MsiGetUserInfoW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiGetUserInfoW szProduct, varptr(lpUserNameBuf), varptr(pcchUserNameBuf), varptr(lpOrgNameBuf), varptr(pcchOrgNameBuf), varptr(lpSerialBuf), varptr(pcchSerialBuf) ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; lpUserNameBuf : LPWSTR optional, out -> "wptr"
; pcchUserNameBuf : DWORD* optional, in/out -> "wptr"
; lpOrgNameBuf : LPWSTR optional, out -> "wptr"
; pcchOrgNameBuf : DWORD* optional, in/out -> "wptr"
; lpSerialBuf : LPWSTR optional, out -> "wptr"
; pcchSerialBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetUserInfoW "MsiGetUserInfoW" wstr, var, var, var, var, var, var ; res = MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf) ; szProduct : LPCWSTR -> "wstr" ; lpUserNameBuf : LPWSTR optional, out -> "var" ; pcchUserNameBuf : DWORD* optional, in/out -> "var" ; lpOrgNameBuf : LPWSTR optional, out -> "var" ; pcchOrgNameBuf : DWORD* optional, in/out -> "var" ; lpSerialBuf : LPWSTR optional, out -> "var" ; pcchSerialBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetUserInfoW "MsiGetUserInfoW" wstr, sptr, sptr, sptr, sptr, sptr, sptr ; res = MsiGetUserInfoW(szProduct, varptr(lpUserNameBuf), varptr(pcchUserNameBuf), varptr(lpOrgNameBuf), varptr(pcchOrgNameBuf), varptr(lpSerialBuf), varptr(pcchSerialBuf)) ; szProduct : LPCWSTR -> "wstr" ; lpUserNameBuf : LPWSTR optional, out -> "sptr" ; pcchUserNameBuf : DWORD* optional, in/out -> "sptr" ; lpOrgNameBuf : LPWSTR optional, out -> "sptr" ; pcchOrgNameBuf : DWORD* optional, in/out -> "sptr" ; lpSerialBuf : LPWSTR optional, out -> "sptr" ; pcchSerialBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; USERINFOSTATE MsiGetUserInfoW(LPCWSTR szProduct, LPWSTR lpUserNameBuf, DWORD* pcchUserNameBuf, LPWSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf, LPWSTR lpSerialBuf, DWORD* pcchSerialBuf) #uselib "msi.dll" #cfunc global MsiGetUserInfoW "MsiGetUserInfoW" wstr, var, var, var, var, var, var ; res = MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf) ; szProduct : LPCWSTR -> "wstr" ; lpUserNameBuf : LPWSTR optional, out -> "var" ; pcchUserNameBuf : DWORD* optional, in/out -> "var" ; lpOrgNameBuf : LPWSTR optional, out -> "var" ; pcchOrgNameBuf : DWORD* optional, in/out -> "var" ; lpSerialBuf : LPWSTR optional, out -> "var" ; pcchSerialBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; USERINFOSTATE MsiGetUserInfoW(LPCWSTR szProduct, LPWSTR lpUserNameBuf, DWORD* pcchUserNameBuf, LPWSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf, LPWSTR lpSerialBuf, DWORD* pcchSerialBuf) #uselib "msi.dll" #cfunc global MsiGetUserInfoW "MsiGetUserInfoW" wstr, intptr, intptr, intptr, intptr, intptr, intptr ; res = MsiGetUserInfoW(szProduct, varptr(lpUserNameBuf), varptr(pcchUserNameBuf), varptr(lpOrgNameBuf), varptr(pcchOrgNameBuf), varptr(lpSerialBuf), varptr(pcchSerialBuf)) ; szProduct : LPCWSTR -> "wstr" ; lpUserNameBuf : LPWSTR optional, out -> "intptr" ; pcchUserNameBuf : DWORD* optional, in/out -> "intptr" ; lpOrgNameBuf : LPWSTR optional, out -> "intptr" ; pcchOrgNameBuf : DWORD* optional, in/out -> "intptr" ; lpSerialBuf : LPWSTR optional, out -> "intptr" ; pcchSerialBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetUserInfoW = msi.NewProc("MsiGetUserInfoW")
)
// szProduct (LPCWSTR), lpUserNameBuf (LPWSTR optional, out), pcchUserNameBuf (DWORD* optional, in/out), lpOrgNameBuf (LPWSTR optional, out), pcchOrgNameBuf (DWORD* optional, in/out), lpSerialBuf (LPWSTR optional, out), pcchSerialBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetUserInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProduct))),
uintptr(lpUserNameBuf),
uintptr(pcchUserNameBuf),
uintptr(lpOrgNameBuf),
uintptr(pcchOrgNameBuf),
uintptr(lpSerialBuf),
uintptr(pcchSerialBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // USERINFOSTATEfunction MsiGetUserInfoW(
szProduct: PWideChar; // LPCWSTR
lpUserNameBuf: PWideChar; // LPWSTR optional, out
pcchUserNameBuf: Pointer; // DWORD* optional, in/out
lpOrgNameBuf: PWideChar; // LPWSTR optional, out
pcchOrgNameBuf: Pointer; // DWORD* optional, in/out
lpSerialBuf: PWideChar; // LPWSTR optional, out
pcchSerialBuf: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'msi.dll' name 'MsiGetUserInfoW';result := DllCall("msi\MsiGetUserInfoW"
, "WStr", szProduct ; LPCWSTR
, "Ptr", lpUserNameBuf ; LPWSTR optional, out
, "Ptr", pcchUserNameBuf ; DWORD* optional, in/out
, "Ptr", lpOrgNameBuf ; LPWSTR optional, out
, "Ptr", pcchOrgNameBuf ; DWORD* optional, in/out
, "Ptr", lpSerialBuf ; LPWSTR optional, out
, "Ptr", pcchSerialBuf ; DWORD* optional, in/out
, "Int") ; return: USERINFOSTATE●MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf) = DLL("msi.dll", "int MsiGetUserInfoW(char*, char*, void*, char*, void*, char*, void*)")
# 呼び出し: MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)
# szProduct : LPCWSTR -> "char*"
# lpUserNameBuf : LPWSTR optional, out -> "char*"
# pcchUserNameBuf : DWORD* optional, in/out -> "void*"
# lpOrgNameBuf : LPWSTR optional, out -> "char*"
# pcchOrgNameBuf : DWORD* optional, in/out -> "void*"
# lpSerialBuf : LPWSTR optional, out -> "char*"
# pcchSerialBuf : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetUserInfoW(
szProduct: [*c]const u16, // LPCWSTR
lpUserNameBuf: [*c]u16, // LPWSTR optional, out
pcchUserNameBuf: [*c]u32, // DWORD* optional, in/out
lpOrgNameBuf: [*c]u16, // LPWSTR optional, out
pcchOrgNameBuf: [*c]u32, // DWORD* optional, in/out
lpSerialBuf: [*c]u16, // LPWSTR optional, out
pcchSerialBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetUserInfoW(
szProduct: WideCString, # LPCWSTR
lpUserNameBuf: ptr uint16, # LPWSTR optional, out
pcchUserNameBuf: ptr uint32, # DWORD* optional, in/out
lpOrgNameBuf: ptr uint16, # LPWSTR optional, out
pcchOrgNameBuf: ptr uint32, # DWORD* optional, in/out
lpSerialBuf: ptr uint16, # LPWSTR optional, out
pcchSerialBuf: ptr uint32 # DWORD* optional, in/out
): int32 {.importc: "MsiGetUserInfoW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
int MsiGetUserInfoW(
const(wchar)* szProduct, // LPCWSTR
wchar* lpUserNameBuf, // LPWSTR optional, out
uint* pcchUserNameBuf, // DWORD* optional, in/out
wchar* lpOrgNameBuf, // LPWSTR optional, out
uint* pcchOrgNameBuf, // DWORD* optional, in/out
wchar* lpSerialBuf, // LPWSTR optional, out
uint* pcchSerialBuf // DWORD* optional, in/out
);ccall((:MsiGetUserInfoW, "msi.dll"), stdcall, Int32,
(Cwstring, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}),
szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)
# szProduct : LPCWSTR -> Cwstring
# lpUserNameBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchUserNameBuf : DWORD* optional, in/out -> Ptr{UInt32}
# lpOrgNameBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchOrgNameBuf : DWORD* optional, in/out -> Ptr{UInt32}
# lpSerialBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchSerialBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t MsiGetUserInfoW(
const uint16_t* szProduct,
uint16_t* lpUserNameBuf,
uint32_t* pcchUserNameBuf,
uint16_t* lpOrgNameBuf,
uint32_t* pcchOrgNameBuf,
uint16_t* lpSerialBuf,
uint32_t* pcchSerialBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)
-- szProduct : LPCWSTR
-- lpUserNameBuf : LPWSTR optional, out
-- pcchUserNameBuf : DWORD* optional, in/out
-- lpOrgNameBuf : LPWSTR optional, out
-- pcchOrgNameBuf : DWORD* optional, in/out
-- lpSerialBuf : LPWSTR optional, out
-- pcchSerialBuf : DWORD* optional, in/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 MsiGetUserInfoW = lib.func('__stdcall', 'MsiGetUserInfoW', 'int32_t', ['str16', 'uint16_t *', 'uint32_t *', 'uint16_t *', 'uint32_t *', 'uint16_t *', 'uint32_t *']);
// MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)
// szProduct : LPCWSTR -> 'str16'
// lpUserNameBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchUserNameBuf : DWORD* optional, in/out -> 'uint32_t *'
// lpOrgNameBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchOrgNameBuf : DWORD* optional, in/out -> 'uint32_t *'
// lpSerialBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchSerialBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetUserInfoW: { parameters: ["buffer", "buffer", "pointer", "buffer", "pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf)
// szProduct : LPCWSTR -> "buffer"
// lpUserNameBuf : LPWSTR optional, out -> "buffer"
// pcchUserNameBuf : DWORD* optional, in/out -> "pointer"
// lpOrgNameBuf : LPWSTR optional, out -> "buffer"
// pcchOrgNameBuf : DWORD* optional, in/out -> "pointer"
// lpSerialBuf : LPWSTR optional, out -> "buffer"
// pcchSerialBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MsiGetUserInfoW(
const uint16_t* szProduct,
uint16_t* lpUserNameBuf,
uint32_t* pcchUserNameBuf,
uint16_t* lpOrgNameBuf,
uint32_t* pcchOrgNameBuf,
uint16_t* lpSerialBuf,
uint32_t* pcchSerialBuf);
C, "msi.dll");
// $ffi->MsiGetUserInfoW(szProduct, lpUserNameBuf, pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf, pcchSerialBuf);
// szProduct : LPCWSTR
// lpUserNameBuf : LPWSTR optional, out
// pcchUserNameBuf : DWORD* optional, in/out
// lpOrgNameBuf : LPWSTR optional, out
// pcchOrgNameBuf : DWORD* optional, in/out
// lpSerialBuf : LPWSTR optional, out
// pcchSerialBuf : DWORD* optional, in/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 MsiGetUserInfoW(
WString szProduct, // LPCWSTR
char[] lpUserNameBuf, // LPWSTR optional, out
IntByReference pcchUserNameBuf, // DWORD* optional, in/out
char[] lpOrgNameBuf, // LPWSTR optional, out
IntByReference pcchOrgNameBuf, // DWORD* optional, in/out
char[] lpSerialBuf, // LPWSTR optional, out
IntByReference pcchSerialBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetUserInfoW = MsiGetUserInfoW(
szProduct : UInt16*, # LPCWSTR
lpUserNameBuf : UInt16*, # LPWSTR optional, out
pcchUserNameBuf : UInt32*, # DWORD* optional, in/out
lpOrgNameBuf : UInt16*, # LPWSTR optional, out
pcchOrgNameBuf : UInt32*, # DWORD* optional, in/out
lpSerialBuf : UInt16*, # LPWSTR optional, out
pcchSerialBuf : UInt32* # DWORD* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetUserInfoWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetUserInfoWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetUserInfoW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetUserInfoWNative, MsiGetUserInfoWDart>('MsiGetUserInfoW');
// szProduct : LPCWSTR -> Pointer<Utf16>
// lpUserNameBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchUserNameBuf : DWORD* optional, in/out -> Pointer<Uint32>
// lpOrgNameBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchOrgNameBuf : DWORD* optional, in/out -> Pointer<Uint32>
// lpSerialBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchSerialBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetUserInfoW(
szProduct: PWideChar; // LPCWSTR
lpUserNameBuf: PWideChar; // LPWSTR optional, out
pcchUserNameBuf: Pointer; // DWORD* optional, in/out
lpOrgNameBuf: PWideChar; // LPWSTR optional, out
pcchOrgNameBuf: Pointer; // DWORD* optional, in/out
lpSerialBuf: PWideChar; // LPWSTR optional, out
pcchSerialBuf: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'msi.dll' name 'MsiGetUserInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetUserInfoW"
c_MsiGetUserInfoW :: CWString -> CWString -> Ptr Word32 -> CWString -> Ptr Word32 -> CWString -> Ptr Word32 -> IO Int32
-- szProduct : LPCWSTR -> CWString
-- lpUserNameBuf : LPWSTR optional, out -> CWString
-- pcchUserNameBuf : DWORD* optional, in/out -> Ptr Word32
-- lpOrgNameBuf : LPWSTR optional, out -> CWString
-- pcchOrgNameBuf : DWORD* optional, in/out -> Ptr Word32
-- lpSerialBuf : LPWSTR optional, out -> CWString
-- pcchSerialBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetuserinfow =
foreign "MsiGetUserInfoW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* szProduct : LPCWSTR -> (ptr uint16_t) *)
(* lpUserNameBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchUserNameBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* lpOrgNameBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchOrgNameBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* lpSerialBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchSerialBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetUserInfoW" msi-get-user-info-w :convention :stdcall) :int32
(sz-product (:string :encoding :utf-16le)) ; LPCWSTR
(lp-user-name-buf :pointer) ; LPWSTR optional, out
(pcch-user-name-buf :pointer) ; DWORD* optional, in/out
(lp-org-name-buf :pointer) ; LPWSTR optional, out
(pcch-org-name-buf :pointer) ; DWORD* optional, in/out
(lp-serial-buf :pointer) ; LPWSTR optional, out
(pcch-serial-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetUserInfoW = Win32::API::More->new('msi',
'int MsiGetUserInfoW(LPCWSTR szProduct, LPWSTR lpUserNameBuf, LPVOID pcchUserNameBuf, LPWSTR lpOrgNameBuf, LPVOID pcchOrgNameBuf, LPWSTR lpSerialBuf, LPVOID pcchSerialBuf)');
# my $ret = $MsiGetUserInfoW->Call($szProduct, $lpUserNameBuf, $pcchUserNameBuf, $lpOrgNameBuf, $pcchOrgNameBuf, $lpSerialBuf, $pcchSerialBuf);
# szProduct : LPCWSTR -> LPCWSTR
# lpUserNameBuf : LPWSTR optional, out -> LPWSTR
# pcchUserNameBuf : DWORD* optional, in/out -> LPVOID
# lpOrgNameBuf : LPWSTR optional, out -> LPWSTR
# pcchOrgNameBuf : DWORD* optional, in/out -> LPVOID
# lpSerialBuf : LPWSTR optional, out -> LPWSTR
# pcchSerialBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f MsiGetUserInfoA (ANSI版) — 製品に登録されたユーザー情報を取得する(ANSI版)。
使用する型