ホーム › System.ClrHosting › GetRequestedRuntimeInfo
GetRequestedRuntimeInfo
関数実行ファイルや構成から要求されるランタイム情報を取得する。
シグネチャ
// MSCorEE.dll
#include <windows.h>
HRESULT GetRequestedRuntimeInfo(
LPCWSTR pExe,
LPCWSTR pwszVersion,
LPCWSTR pConfigurationFile,
DWORD startupFlags,
DWORD runtimeInfoFlags,
LPWSTR pDirectory, // optional
DWORD dwDirectory,
DWORD* dwDirectoryLength, // optional
LPWSTR pVersion, // optional
DWORD cchBuffer,
DWORD* dwlength // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pExe | LPCWSTR | in | 対象実行ファイルのパス。バージョン解決の基準とする。Unicode 文字列。NULL 可。 |
| pwszVersion | LPCWSTR | in | 要求するランタイムバージョン文字列。Unicode 文字列。NULL 可。 |
| pConfigurationFile | LPCWSTR | in | 構成ファイル(app.config)のパス。Unicode 文字列。NULL 可。 |
| startupFlags | DWORD | in | ランタイム起動動作を制御する STARTUP_FLAGS。 |
| runtimeInfoFlags | DWORD | in | バージョン解決動作を制御する RUNTIME_INFO_FLAGS。 |
| pDirectory | LPWSTR | outoptional | 解決されたランタイムのディレクトリパスを受け取る出力バッファ。Unicode 文字列。 |
| dwDirectory | DWORD | in | pDirectory のサイズ。文字数で指定する。 |
| dwDirectoryLength | DWORD* | outoptional | pDirectory に書き込まれた文字数を受け取る出力ポインタ。 |
| pVersion | LPWSTR | outoptional | 解決されたランタイムバージョン文字列を受け取る出力バッファ。Unicode 文字列。 |
| cchBuffer | DWORD | in | pVersion のサイズ。文字数で指定する。 |
| dwlength | DWORD* | outoptional | pVersion に書き込まれた文字数を受け取る出力ポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// MSCorEE.dll
#include <windows.h>
HRESULT GetRequestedRuntimeInfo(
LPCWSTR pExe,
LPCWSTR pwszVersion,
LPCWSTR pConfigurationFile,
DWORD startupFlags,
DWORD runtimeInfoFlags,
LPWSTR pDirectory, // optional
DWORD dwDirectory,
DWORD* dwDirectoryLength, // optional
LPWSTR pVersion, // optional
DWORD cchBuffer,
DWORD* dwlength // optional
);[DllImport("MSCorEE.dll", ExactSpelling = true)]
static extern int GetRequestedRuntimeInfo(
[MarshalAs(UnmanagedType.LPWStr)] string pExe, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pwszVersion, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pConfigurationFile, // LPCWSTR
uint startupFlags, // DWORD
uint runtimeInfoFlags, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pDirectory, // LPWSTR optional, out
uint dwDirectory, // DWORD
IntPtr dwDirectoryLength, // DWORD* optional, out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pVersion, // LPWSTR optional, out
uint cchBuffer, // DWORD
IntPtr dwlength // DWORD* optional, out
);<DllImport("MSCorEE.dll", ExactSpelling:=True)>
Public Shared Function GetRequestedRuntimeInfo(
<MarshalAs(UnmanagedType.LPWStr)> pExe As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pwszVersion As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pConfigurationFile As String, ' LPCWSTR
startupFlags As UInteger, ' DWORD
runtimeInfoFlags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pDirectory As System.Text.StringBuilder, ' LPWSTR optional, out
dwDirectory As UInteger, ' DWORD
dwDirectoryLength As IntPtr, ' DWORD* optional, out
<MarshalAs(UnmanagedType.LPWStr)> pVersion As System.Text.StringBuilder, ' LPWSTR optional, out
cchBuffer As UInteger, ' DWORD
dwlength As IntPtr ' DWORD* optional, out
) As Integer
End Function' pExe : LPCWSTR
' pwszVersion : LPCWSTR
' pConfigurationFile : LPCWSTR
' startupFlags : DWORD
' runtimeInfoFlags : DWORD
' pDirectory : LPWSTR optional, out
' dwDirectory : DWORD
' dwDirectoryLength : DWORD* optional, out
' pVersion : LPWSTR optional, out
' cchBuffer : DWORD
' dwlength : DWORD* optional, out
Declare PtrSafe Function GetRequestedRuntimeInfo Lib "mscoree" ( _
ByVal pExe As LongPtr, _
ByVal pwszVersion As LongPtr, _
ByVal pConfigurationFile As LongPtr, _
ByVal startupFlags As Long, _
ByVal runtimeInfoFlags As Long, _
ByVal pDirectory As LongPtr, _
ByVal dwDirectory As Long, _
ByVal dwDirectoryLength As LongPtr, _
ByVal pVersion As LongPtr, _
ByVal cchBuffer As Long, _
ByVal dwlength As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetRequestedRuntimeInfo = ctypes.windll.mscoree.GetRequestedRuntimeInfo
GetRequestedRuntimeInfo.restype = ctypes.c_int
GetRequestedRuntimeInfo.argtypes = [
wintypes.LPCWSTR, # pExe : LPCWSTR
wintypes.LPCWSTR, # pwszVersion : LPCWSTR
wintypes.LPCWSTR, # pConfigurationFile : LPCWSTR
wintypes.DWORD, # startupFlags : DWORD
wintypes.DWORD, # runtimeInfoFlags : DWORD
wintypes.LPWSTR, # pDirectory : LPWSTR optional, out
wintypes.DWORD, # dwDirectory : DWORD
ctypes.POINTER(wintypes.DWORD), # dwDirectoryLength : DWORD* optional, out
wintypes.LPWSTR, # pVersion : LPWSTR optional, out
wintypes.DWORD, # cchBuffer : DWORD
ctypes.POINTER(wintypes.DWORD), # dwlength : DWORD* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MSCorEE.dll')
GetRequestedRuntimeInfo = Fiddle::Function.new(
lib['GetRequestedRuntimeInfo'],
[
Fiddle::TYPE_VOIDP, # pExe : LPCWSTR
Fiddle::TYPE_VOIDP, # pwszVersion : LPCWSTR
Fiddle::TYPE_VOIDP, # pConfigurationFile : LPCWSTR
-Fiddle::TYPE_INT, # startupFlags : DWORD
-Fiddle::TYPE_INT, # runtimeInfoFlags : DWORD
Fiddle::TYPE_VOIDP, # pDirectory : LPWSTR optional, out
-Fiddle::TYPE_INT, # dwDirectory : DWORD
Fiddle::TYPE_VOIDP, # dwDirectoryLength : DWORD* optional, out
Fiddle::TYPE_VOIDP, # pVersion : LPWSTR optional, out
-Fiddle::TYPE_INT, # cchBuffer : DWORD
Fiddle::TYPE_VOIDP, # dwlength : DWORD* optional, out
],
Fiddle::TYPE_INT)#[link(name = "mscoree")]
extern "system" {
fn GetRequestedRuntimeInfo(
pExe: *const u16, // LPCWSTR
pwszVersion: *const u16, // LPCWSTR
pConfigurationFile: *const u16, // LPCWSTR
startupFlags: u32, // DWORD
runtimeInfoFlags: u32, // DWORD
pDirectory: *mut u16, // LPWSTR optional, out
dwDirectory: u32, // DWORD
dwDirectoryLength: *mut u32, // DWORD* optional, out
pVersion: *mut u16, // LPWSTR optional, out
cchBuffer: u32, // DWORD
dwlength: *mut u32 // DWORD* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MSCorEE.dll")]
public static extern int GetRequestedRuntimeInfo([MarshalAs(UnmanagedType.LPWStr)] string pExe, [MarshalAs(UnmanagedType.LPWStr)] string pwszVersion, [MarshalAs(UnmanagedType.LPWStr)] string pConfigurationFile, uint startupFlags, uint runtimeInfoFlags, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pDirectory, uint dwDirectory, IntPtr dwDirectoryLength, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pVersion, uint cchBuffer, IntPtr dwlength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSCorEE_GetRequestedRuntimeInfo' -Namespace Win32 -PassThru
# $api::GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)#uselib "MSCorEE.dll"
#func global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetRequestedRuntimeInfo pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, varptr(pDirectory), dwDirectory, varptr(dwDirectoryLength), varptr(pVersion), cchBuffer, varptr(dwlength) ; 戻り値は stat
; pExe : LPCWSTR -> "sptr"
; pwszVersion : LPCWSTR -> "sptr"
; pConfigurationFile : LPCWSTR -> "sptr"
; startupFlags : DWORD -> "sptr"
; runtimeInfoFlags : DWORD -> "sptr"
; pDirectory : LPWSTR optional, out -> "sptr"
; dwDirectory : DWORD -> "sptr"
; dwDirectoryLength : DWORD* optional, out -> "sptr"
; pVersion : LPWSTR optional, out -> "sptr"
; cchBuffer : DWORD -> "sptr"
; dwlength : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MSCorEE.dll" #cfunc global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" wstr, wstr, wstr, int, int, var, int, var, var, int, var ; res = GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength) ; pExe : LPCWSTR -> "wstr" ; pwszVersion : LPCWSTR -> "wstr" ; pConfigurationFile : LPCWSTR -> "wstr" ; startupFlags : DWORD -> "int" ; runtimeInfoFlags : DWORD -> "int" ; pDirectory : LPWSTR optional, out -> "var" ; dwDirectory : DWORD -> "int" ; dwDirectoryLength : DWORD* optional, out -> "var" ; pVersion : LPWSTR optional, out -> "var" ; cchBuffer : DWORD -> "int" ; dwlength : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MSCorEE.dll" #cfunc global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" wstr, wstr, wstr, int, int, sptr, int, sptr, sptr, int, sptr ; res = GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, varptr(pDirectory), dwDirectory, varptr(dwDirectoryLength), varptr(pVersion), cchBuffer, varptr(dwlength)) ; pExe : LPCWSTR -> "wstr" ; pwszVersion : LPCWSTR -> "wstr" ; pConfigurationFile : LPCWSTR -> "wstr" ; startupFlags : DWORD -> "int" ; runtimeInfoFlags : DWORD -> "int" ; pDirectory : LPWSTR optional, out -> "sptr" ; dwDirectory : DWORD -> "int" ; dwDirectoryLength : DWORD* optional, out -> "sptr" ; pVersion : LPWSTR optional, out -> "sptr" ; cchBuffer : DWORD -> "int" ; dwlength : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile, DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD* dwDirectoryLength, LPWSTR pVersion, DWORD cchBuffer, DWORD* dwlength) #uselib "MSCorEE.dll" #cfunc global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" wstr, wstr, wstr, int, int, var, int, var, var, int, var ; res = GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength) ; pExe : LPCWSTR -> "wstr" ; pwszVersion : LPCWSTR -> "wstr" ; pConfigurationFile : LPCWSTR -> "wstr" ; startupFlags : DWORD -> "int" ; runtimeInfoFlags : DWORD -> "int" ; pDirectory : LPWSTR optional, out -> "var" ; dwDirectory : DWORD -> "int" ; dwDirectoryLength : DWORD* optional, out -> "var" ; pVersion : LPWSTR optional, out -> "var" ; cchBuffer : DWORD -> "int" ; dwlength : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile, DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD* dwDirectoryLength, LPWSTR pVersion, DWORD cchBuffer, DWORD* dwlength) #uselib "MSCorEE.dll" #cfunc global GetRequestedRuntimeInfo "GetRequestedRuntimeInfo" wstr, wstr, wstr, int, int, intptr, int, intptr, intptr, int, intptr ; res = GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, varptr(pDirectory), dwDirectory, varptr(dwDirectoryLength), varptr(pVersion), cchBuffer, varptr(dwlength)) ; pExe : LPCWSTR -> "wstr" ; pwszVersion : LPCWSTR -> "wstr" ; pConfigurationFile : LPCWSTR -> "wstr" ; startupFlags : DWORD -> "int" ; runtimeInfoFlags : DWORD -> "int" ; pDirectory : LPWSTR optional, out -> "intptr" ; dwDirectory : DWORD -> "int" ; dwDirectoryLength : DWORD* optional, out -> "intptr" ; pVersion : LPWSTR optional, out -> "intptr" ; cchBuffer : DWORD -> "int" ; dwlength : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mscoree = windows.NewLazySystemDLL("MSCorEE.dll")
procGetRequestedRuntimeInfo = mscoree.NewProc("GetRequestedRuntimeInfo")
)
// pExe (LPCWSTR), pwszVersion (LPCWSTR), pConfigurationFile (LPCWSTR), startupFlags (DWORD), runtimeInfoFlags (DWORD), pDirectory (LPWSTR optional, out), dwDirectory (DWORD), dwDirectoryLength (DWORD* optional, out), pVersion (LPWSTR optional, out), cchBuffer (DWORD), dwlength (DWORD* optional, out)
r1, _, err := procGetRequestedRuntimeInfo.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pExe))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszVersion))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pConfigurationFile))),
uintptr(startupFlags),
uintptr(runtimeInfoFlags),
uintptr(pDirectory),
uintptr(dwDirectory),
uintptr(dwDirectoryLength),
uintptr(pVersion),
uintptr(cchBuffer),
uintptr(dwlength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetRequestedRuntimeInfo(
pExe: PWideChar; // LPCWSTR
pwszVersion: PWideChar; // LPCWSTR
pConfigurationFile: PWideChar; // LPCWSTR
startupFlags: DWORD; // DWORD
runtimeInfoFlags: DWORD; // DWORD
pDirectory: PWideChar; // LPWSTR optional, out
dwDirectory: DWORD; // DWORD
dwDirectoryLength: Pointer; // DWORD* optional, out
pVersion: PWideChar; // LPWSTR optional, out
cchBuffer: DWORD; // DWORD
dwlength: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'MSCorEE.dll' name 'GetRequestedRuntimeInfo';result := DllCall("MSCorEE\GetRequestedRuntimeInfo"
, "WStr", pExe ; LPCWSTR
, "WStr", pwszVersion ; LPCWSTR
, "WStr", pConfigurationFile ; LPCWSTR
, "UInt", startupFlags ; DWORD
, "UInt", runtimeInfoFlags ; DWORD
, "Ptr", pDirectory ; LPWSTR optional, out
, "UInt", dwDirectory ; DWORD
, "Ptr", dwDirectoryLength ; DWORD* optional, out
, "Ptr", pVersion ; LPWSTR optional, out
, "UInt", cchBuffer ; DWORD
, "Ptr", dwlength ; DWORD* optional, out
, "Int") ; return: HRESULT●GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength) = DLL("MSCorEE.dll", "int GetRequestedRuntimeInfo(char*, char*, char*, dword, dword, char*, dword, void*, char*, dword, void*)")
# 呼び出し: GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)
# pExe : LPCWSTR -> "char*"
# pwszVersion : LPCWSTR -> "char*"
# pConfigurationFile : LPCWSTR -> "char*"
# startupFlags : DWORD -> "dword"
# runtimeInfoFlags : DWORD -> "dword"
# pDirectory : LPWSTR optional, out -> "char*"
# dwDirectory : DWORD -> "dword"
# dwDirectoryLength : DWORD* optional, out -> "void*"
# pVersion : LPWSTR optional, out -> "char*"
# cchBuffer : DWORD -> "dword"
# dwlength : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mscoree" fn GetRequestedRuntimeInfo(
pExe: [*c]const u16, // LPCWSTR
pwszVersion: [*c]const u16, // LPCWSTR
pConfigurationFile: [*c]const u16, // LPCWSTR
startupFlags: u32, // DWORD
runtimeInfoFlags: u32, // DWORD
pDirectory: [*c]u16, // LPWSTR optional, out
dwDirectory: u32, // DWORD
dwDirectoryLength: [*c]u32, // DWORD* optional, out
pVersion: [*c]u16, // LPWSTR optional, out
cchBuffer: u32, // DWORD
dwlength: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc GetRequestedRuntimeInfo(
pExe: WideCString, # LPCWSTR
pwszVersion: WideCString, # LPCWSTR
pConfigurationFile: WideCString, # LPCWSTR
startupFlags: uint32, # DWORD
runtimeInfoFlags: uint32, # DWORD
pDirectory: ptr uint16, # LPWSTR optional, out
dwDirectory: uint32, # DWORD
dwDirectoryLength: ptr uint32, # DWORD* optional, out
pVersion: ptr uint16, # LPWSTR optional, out
cchBuffer: uint32, # DWORD
dwlength: ptr uint32 # DWORD* optional, out
): int32 {.importc: "GetRequestedRuntimeInfo", stdcall, dynlib: "MSCorEE.dll".}pragma(lib, "mscoree");
extern(Windows)
int GetRequestedRuntimeInfo(
const(wchar)* pExe, // LPCWSTR
const(wchar)* pwszVersion, // LPCWSTR
const(wchar)* pConfigurationFile, // LPCWSTR
uint startupFlags, // DWORD
uint runtimeInfoFlags, // DWORD
wchar* pDirectory, // LPWSTR optional, out
uint dwDirectory, // DWORD
uint* dwDirectoryLength, // DWORD* optional, out
wchar* pVersion, // LPWSTR optional, out
uint cchBuffer, // DWORD
uint* dwlength // DWORD* optional, out
);ccall((:GetRequestedRuntimeInfo, "MSCorEE.dll"), stdcall, Int32,
(Cwstring, Cwstring, Cwstring, UInt32, UInt32, Ptr{UInt16}, UInt32, Ptr{UInt32}, Ptr{UInt16}, UInt32, Ptr{UInt32}),
pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)
# pExe : LPCWSTR -> Cwstring
# pwszVersion : LPCWSTR -> Cwstring
# pConfigurationFile : LPCWSTR -> Cwstring
# startupFlags : DWORD -> UInt32
# runtimeInfoFlags : DWORD -> UInt32
# pDirectory : LPWSTR optional, out -> Ptr{UInt16}
# dwDirectory : DWORD -> UInt32
# dwDirectoryLength : DWORD* optional, out -> Ptr{UInt32}
# pVersion : LPWSTR optional, out -> Ptr{UInt16}
# cchBuffer : DWORD -> UInt32
# dwlength : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetRequestedRuntimeInfo(
const uint16_t* pExe,
const uint16_t* pwszVersion,
const uint16_t* pConfigurationFile,
uint32_t startupFlags,
uint32_t runtimeInfoFlags,
uint16_t* pDirectory,
uint32_t dwDirectory,
uint32_t* dwDirectoryLength,
uint16_t* pVersion,
uint32_t cchBuffer,
uint32_t* dwlength);
]]
local mscoree = ffi.load("mscoree")
-- mscoree.GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)
-- pExe : LPCWSTR
-- pwszVersion : LPCWSTR
-- pConfigurationFile : LPCWSTR
-- startupFlags : DWORD
-- runtimeInfoFlags : DWORD
-- pDirectory : LPWSTR optional, out
-- dwDirectory : DWORD
-- dwDirectoryLength : DWORD* optional, out
-- pVersion : LPWSTR optional, out
-- cchBuffer : DWORD
-- dwlength : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MSCorEE.dll');
const GetRequestedRuntimeInfo = lib.func('__stdcall', 'GetRequestedRuntimeInfo', 'int32_t', ['str16', 'str16', 'str16', 'uint32_t', 'uint32_t', 'uint16_t *', 'uint32_t', 'uint32_t *', 'uint16_t *', 'uint32_t', 'uint32_t *']);
// GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)
// pExe : LPCWSTR -> 'str16'
// pwszVersion : LPCWSTR -> 'str16'
// pConfigurationFile : LPCWSTR -> 'str16'
// startupFlags : DWORD -> 'uint32_t'
// runtimeInfoFlags : DWORD -> 'uint32_t'
// pDirectory : LPWSTR optional, out -> 'uint16_t *'
// dwDirectory : DWORD -> 'uint32_t'
// dwDirectoryLength : DWORD* optional, out -> 'uint32_t *'
// pVersion : LPWSTR optional, out -> 'uint16_t *'
// cchBuffer : DWORD -> 'uint32_t'
// dwlength : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MSCorEE.dll", {
GetRequestedRuntimeInfo: { parameters: ["buffer", "buffer", "buffer", "u32", "u32", "buffer", "u32", "pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength)
// pExe : LPCWSTR -> "buffer"
// pwszVersion : LPCWSTR -> "buffer"
// pConfigurationFile : LPCWSTR -> "buffer"
// startupFlags : DWORD -> "u32"
// runtimeInfoFlags : DWORD -> "u32"
// pDirectory : LPWSTR optional, out -> "buffer"
// dwDirectory : DWORD -> "u32"
// dwDirectoryLength : DWORD* optional, out -> "pointer"
// pVersion : LPWSTR optional, out -> "buffer"
// cchBuffer : DWORD -> "u32"
// dwlength : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetRequestedRuntimeInfo(
const uint16_t* pExe,
const uint16_t* pwszVersion,
const uint16_t* pConfigurationFile,
uint32_t startupFlags,
uint32_t runtimeInfoFlags,
uint16_t* pDirectory,
uint32_t dwDirectory,
uint32_t* dwDirectoryLength,
uint16_t* pVersion,
uint32_t cchBuffer,
uint32_t* dwlength);
C, "MSCorEE.dll");
// $ffi->GetRequestedRuntimeInfo(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, pDirectory, dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
// pExe : LPCWSTR
// pwszVersion : LPCWSTR
// pConfigurationFile : LPCWSTR
// startupFlags : DWORD
// runtimeInfoFlags : DWORD
// pDirectory : LPWSTR optional, out
// dwDirectory : DWORD
// dwDirectoryLength : DWORD* optional, out
// pVersion : LPWSTR optional, out
// cchBuffer : DWORD
// dwlength : DWORD* 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 Mscoree extends StdCallLibrary {
Mscoree INSTANCE = Native.load("mscoree", Mscoree.class);
int GetRequestedRuntimeInfo(
WString pExe, // LPCWSTR
WString pwszVersion, // LPCWSTR
WString pConfigurationFile, // LPCWSTR
int startupFlags, // DWORD
int runtimeInfoFlags, // DWORD
char[] pDirectory, // LPWSTR optional, out
int dwDirectory, // DWORD
IntByReference dwDirectoryLength, // DWORD* optional, out
char[] pVersion, // LPWSTR optional, out
int cchBuffer, // DWORD
IntByReference dwlength // DWORD* optional, out
);
}@[Link("mscoree")]
lib LibMSCorEE
fun GetRequestedRuntimeInfo = GetRequestedRuntimeInfo(
pExe : UInt16*, # LPCWSTR
pwszVersion : UInt16*, # LPCWSTR
pConfigurationFile : UInt16*, # LPCWSTR
startupFlags : UInt32, # DWORD
runtimeInfoFlags : UInt32, # DWORD
pDirectory : UInt16*, # LPWSTR optional, out
dwDirectory : UInt32, # DWORD
dwDirectoryLength : UInt32*, # DWORD* optional, out
pVersion : UInt16*, # LPWSTR optional, out
cchBuffer : UInt32, # DWORD
dwlength : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetRequestedRuntimeInfoNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Uint32, Pointer<Uint32>, Pointer<Utf16>, Uint32, Pointer<Uint32>);
typedef GetRequestedRuntimeInfoDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Utf16>, int, Pointer<Uint32>, Pointer<Utf16>, int, Pointer<Uint32>);
final GetRequestedRuntimeInfo = DynamicLibrary.open('MSCorEE.dll')
.lookupFunction<GetRequestedRuntimeInfoNative, GetRequestedRuntimeInfoDart>('GetRequestedRuntimeInfo');
// pExe : LPCWSTR -> Pointer<Utf16>
// pwszVersion : LPCWSTR -> Pointer<Utf16>
// pConfigurationFile : LPCWSTR -> Pointer<Utf16>
// startupFlags : DWORD -> Uint32
// runtimeInfoFlags : DWORD -> Uint32
// pDirectory : LPWSTR optional, out -> Pointer<Utf16>
// dwDirectory : DWORD -> Uint32
// dwDirectoryLength : DWORD* optional, out -> Pointer<Uint32>
// pVersion : LPWSTR optional, out -> Pointer<Utf16>
// cchBuffer : DWORD -> Uint32
// dwlength : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetRequestedRuntimeInfo(
pExe: PWideChar; // LPCWSTR
pwszVersion: PWideChar; // LPCWSTR
pConfigurationFile: PWideChar; // LPCWSTR
startupFlags: DWORD; // DWORD
runtimeInfoFlags: DWORD; // DWORD
pDirectory: PWideChar; // LPWSTR optional, out
dwDirectory: DWORD; // DWORD
dwDirectoryLength: Pointer; // DWORD* optional, out
pVersion: PWideChar; // LPWSTR optional, out
cchBuffer: DWORD; // DWORD
dwlength: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'MSCorEE.dll' name 'GetRequestedRuntimeInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetRequestedRuntimeInfo"
c_GetRequestedRuntimeInfo :: CWString -> CWString -> CWString -> Word32 -> Word32 -> CWString -> Word32 -> Ptr Word32 -> CWString -> Word32 -> Ptr Word32 -> IO Int32
-- pExe : LPCWSTR -> CWString
-- pwszVersion : LPCWSTR -> CWString
-- pConfigurationFile : LPCWSTR -> CWString
-- startupFlags : DWORD -> Word32
-- runtimeInfoFlags : DWORD -> Word32
-- pDirectory : LPWSTR optional, out -> CWString
-- dwDirectory : DWORD -> Word32
-- dwDirectoryLength : DWORD* optional, out -> Ptr Word32
-- pVersion : LPWSTR optional, out -> CWString
-- cchBuffer : DWORD -> Word32
-- dwlength : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getrequestedruntimeinfo =
foreign "GetRequestedRuntimeInfo"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* pExe : LPCWSTR -> (ptr uint16_t) *)
(* pwszVersion : LPCWSTR -> (ptr uint16_t) *)
(* pConfigurationFile : LPCWSTR -> (ptr uint16_t) *)
(* startupFlags : DWORD -> uint32_t *)
(* runtimeInfoFlags : DWORD -> uint32_t *)
(* pDirectory : LPWSTR optional, out -> (ptr uint16_t) *)
(* dwDirectory : DWORD -> uint32_t *)
(* dwDirectoryLength : DWORD* optional, out -> (ptr uint32_t) *)
(* pVersion : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchBuffer : DWORD -> uint32_t *)
(* dwlength : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mscoree (t "MSCorEE.dll"))
(cffi:use-foreign-library mscoree)
(cffi:defcfun ("GetRequestedRuntimeInfo" get-requested-runtime-info :convention :stdcall) :int32
(p-exe (:string :encoding :utf-16le)) ; LPCWSTR
(pwsz-version (:string :encoding :utf-16le)) ; LPCWSTR
(p-configuration-file (:string :encoding :utf-16le)) ; LPCWSTR
(startup-flags :uint32) ; DWORD
(runtime-info-flags :uint32) ; DWORD
(p-directory :pointer) ; LPWSTR optional, out
(dw-directory :uint32) ; DWORD
(dw-directory-length :pointer) ; DWORD* optional, out
(p-version :pointer) ; LPWSTR optional, out
(cch-buffer :uint32) ; DWORD
(dwlength :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetRequestedRuntimeInfo = Win32::API::More->new('MSCorEE',
'int GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile, DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, LPVOID dwDirectoryLength, LPWSTR pVersion, DWORD cchBuffer, LPVOID dwlength)');
# my $ret = $GetRequestedRuntimeInfo->Call($pExe, $pwszVersion, $pConfigurationFile, $startupFlags, $runtimeInfoFlags, $pDirectory, $dwDirectory, $dwDirectoryLength, $pVersion, $cchBuffer, $dwlength);
# pExe : LPCWSTR -> LPCWSTR
# pwszVersion : LPCWSTR -> LPCWSTR
# pConfigurationFile : LPCWSTR -> LPCWSTR
# startupFlags : DWORD -> DWORD
# runtimeInfoFlags : DWORD -> DWORD
# pDirectory : LPWSTR optional, out -> LPWSTR
# dwDirectory : DWORD -> DWORD
# dwDirectoryLength : DWORD* optional, out -> LPVOID
# pVersion : LPWSTR optional, out -> LPWSTR
# cchBuffer : DWORD -> DWORD
# dwlength : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。