ホーム › System.ClrHosting › CallFunctionShim
CallFunctionShim
関数指定したDLLの関数をバージョン指定で呼び出すシムを実行する。
シグネチャ
// MSCorEE.dll
#include <windows.h>
HRESULT CallFunctionShim(
LPCWSTR szDllName,
LPCSTR szFunctionName,
void* lpvArgument1,
void* lpvArgument2,
LPCWSTR szVersion,
void* pvReserved
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| szDllName | LPCWSTR | in | 呼び出す関数を含む DLL の名前。Unicode 文字列で指定する。 |
| szFunctionName | LPCSTR | in | 呼び出すエクスポート関数の名前。ANSI 文字列で指定する。 |
| lpvArgument1 | void* | inout | 対象関数に渡す第1引数のポインタ。用途は関数依存。NULL 可。 |
| lpvArgument2 | void* | inout | 対象関数に渡す第2引数のポインタ。用途は関数依存。NULL 可。 |
| szVersion | LPCWSTR | in | 対象 DLL を解決する CLR バージョン文字列。Unicode 文字列。NULL で既定。 |
| pvReserved | void* | inout | 予約済み。NULL を指定する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// MSCorEE.dll
#include <windows.h>
HRESULT CallFunctionShim(
LPCWSTR szDllName,
LPCSTR szFunctionName,
void* lpvArgument1,
void* lpvArgument2,
LPCWSTR szVersion,
void* pvReserved
);[DllImport("MSCorEE.dll", ExactSpelling = true)]
static extern int CallFunctionShim(
[MarshalAs(UnmanagedType.LPWStr)] string szDllName, // LPCWSTR
[MarshalAs(UnmanagedType.LPStr)] string szFunctionName, // LPCSTR
IntPtr lpvArgument1, // void* in/out
IntPtr lpvArgument2, // void* in/out
[MarshalAs(UnmanagedType.LPWStr)] string szVersion, // LPCWSTR
IntPtr pvReserved // void* in/out
);<DllImport("MSCorEE.dll", ExactSpelling:=True)>
Public Shared Function CallFunctionShim(
<MarshalAs(UnmanagedType.LPWStr)> szDllName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPStr)> szFunctionName As String, ' LPCSTR
lpvArgument1 As IntPtr, ' void* in/out
lpvArgument2 As IntPtr, ' void* in/out
<MarshalAs(UnmanagedType.LPWStr)> szVersion As String, ' LPCWSTR
pvReserved As IntPtr ' void* in/out
) As Integer
End Function' szDllName : LPCWSTR
' szFunctionName : LPCSTR
' lpvArgument1 : void* in/out
' lpvArgument2 : void* in/out
' szVersion : LPCWSTR
' pvReserved : void* in/out
Declare PtrSafe Function CallFunctionShim Lib "mscoree" ( _
ByVal szDllName As LongPtr, _
ByVal szFunctionName As String, _
ByVal lpvArgument1 As LongPtr, _
ByVal lpvArgument2 As LongPtr, _
ByVal szVersion As LongPtr, _
ByVal pvReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CallFunctionShim = ctypes.windll.mscoree.CallFunctionShim
CallFunctionShim.restype = ctypes.c_int
CallFunctionShim.argtypes = [
wintypes.LPCWSTR, # szDllName : LPCWSTR
wintypes.LPCSTR, # szFunctionName : LPCSTR
ctypes.POINTER(None), # lpvArgument1 : void* in/out
ctypes.POINTER(None), # lpvArgument2 : void* in/out
wintypes.LPCWSTR, # szVersion : LPCWSTR
ctypes.POINTER(None), # pvReserved : void* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MSCorEE.dll')
CallFunctionShim = Fiddle::Function.new(
lib['CallFunctionShim'],
[
Fiddle::TYPE_VOIDP, # szDllName : LPCWSTR
Fiddle::TYPE_VOIDP, # szFunctionName : LPCSTR
Fiddle::TYPE_VOIDP, # lpvArgument1 : void* in/out
Fiddle::TYPE_VOIDP, # lpvArgument2 : void* in/out
Fiddle::TYPE_VOIDP, # szVersion : LPCWSTR
Fiddle::TYPE_VOIDP, # pvReserved : void* in/out
],
Fiddle::TYPE_INT)#[link(name = "mscoree")]
extern "system" {
fn CallFunctionShim(
szDllName: *const u16, // LPCWSTR
szFunctionName: *const u8, // LPCSTR
lpvArgument1: *mut (), // void* in/out
lpvArgument2: *mut (), // void* in/out
szVersion: *const u16, // LPCWSTR
pvReserved: *mut () // void* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MSCorEE.dll")]
public static extern int CallFunctionShim([MarshalAs(UnmanagedType.LPWStr)] string szDllName, [MarshalAs(UnmanagedType.LPStr)] string szFunctionName, IntPtr lpvArgument1, IntPtr lpvArgument2, [MarshalAs(UnmanagedType.LPWStr)] string szVersion, IntPtr pvReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSCorEE_CallFunctionShim' -Namespace Win32 -PassThru
# $api::CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)#uselib "MSCorEE.dll"
#func global CallFunctionShim "CallFunctionShim" sptr, sptr, sptr, sptr, sptr, sptr
; CallFunctionShim szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved ; 戻り値は stat
; szDllName : LPCWSTR -> "sptr"
; szFunctionName : LPCSTR -> "sptr"
; lpvArgument1 : void* in/out -> "sptr"
; lpvArgument2 : void* in/out -> "sptr"
; szVersion : LPCWSTR -> "sptr"
; pvReserved : void* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "MSCorEE.dll"
#cfunc global CallFunctionShim "CallFunctionShim" wstr, str, sptr, sptr, wstr, sptr
; res = CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
; szDllName : LPCWSTR -> "wstr"
; szFunctionName : LPCSTR -> "str"
; lpvArgument1 : void* in/out -> "sptr"
; lpvArgument2 : void* in/out -> "sptr"
; szVersion : LPCWSTR -> "wstr"
; pvReserved : void* in/out -> "sptr"; HRESULT CallFunctionShim(LPCWSTR szDllName, LPCSTR szFunctionName, void* lpvArgument1, void* lpvArgument2, LPCWSTR szVersion, void* pvReserved)
#uselib "MSCorEE.dll"
#cfunc global CallFunctionShim "CallFunctionShim" wstr, str, intptr, intptr, wstr, intptr
; res = CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
; szDllName : LPCWSTR -> "wstr"
; szFunctionName : LPCSTR -> "str"
; lpvArgument1 : void* in/out -> "intptr"
; lpvArgument2 : void* in/out -> "intptr"
; szVersion : LPCWSTR -> "wstr"
; pvReserved : void* in/out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mscoree = windows.NewLazySystemDLL("MSCorEE.dll")
procCallFunctionShim = mscoree.NewProc("CallFunctionShim")
)
// szDllName (LPCWSTR), szFunctionName (LPCSTR), lpvArgument1 (void* in/out), lpvArgument2 (void* in/out), szVersion (LPCWSTR), pvReserved (void* in/out)
r1, _, err := procCallFunctionShim.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szDllName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szFunctionName))),
uintptr(lpvArgument1),
uintptr(lpvArgument2),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szVersion))),
uintptr(pvReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CallFunctionShim(
szDllName: PWideChar; // LPCWSTR
szFunctionName: PAnsiChar; // LPCSTR
lpvArgument1: Pointer; // void* in/out
lpvArgument2: Pointer; // void* in/out
szVersion: PWideChar; // LPCWSTR
pvReserved: Pointer // void* in/out
): Integer; stdcall;
external 'MSCorEE.dll' name 'CallFunctionShim';result := DllCall("MSCorEE\CallFunctionShim"
, "WStr", szDllName ; LPCWSTR
, "AStr", szFunctionName ; LPCSTR
, "Ptr", lpvArgument1 ; void* in/out
, "Ptr", lpvArgument2 ; void* in/out
, "WStr", szVersion ; LPCWSTR
, "Ptr", pvReserved ; void* in/out
, "Int") ; return: HRESULT●CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved) = DLL("MSCorEE.dll", "int CallFunctionShim(char*, char*, void*, void*, char*, void*)")
# 呼び出し: CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
# szDllName : LPCWSTR -> "char*"
# szFunctionName : LPCSTR -> "char*"
# lpvArgument1 : void* in/out -> "void*"
# lpvArgument2 : void* in/out -> "void*"
# szVersion : LPCWSTR -> "char*"
# pvReserved : void* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mscoree" fn CallFunctionShim(
szDllName: [*c]const u16, // LPCWSTR
szFunctionName: [*c]const u8, // LPCSTR
lpvArgument1: ?*anyopaque, // void* in/out
lpvArgument2: ?*anyopaque, // void* in/out
szVersion: [*c]const u16, // LPCWSTR
pvReserved: ?*anyopaque // void* in/out
) callconv(std.os.windows.WINAPI) i32;proc CallFunctionShim(
szDllName: WideCString, # LPCWSTR
szFunctionName: cstring, # LPCSTR
lpvArgument1: pointer, # void* in/out
lpvArgument2: pointer, # void* in/out
szVersion: WideCString, # LPCWSTR
pvReserved: pointer # void* in/out
): int32 {.importc: "CallFunctionShim", stdcall, dynlib: "MSCorEE.dll".}pragma(lib, "mscoree");
extern(Windows)
int CallFunctionShim(
const(wchar)* szDllName, // LPCWSTR
const(char)* szFunctionName, // LPCSTR
void* lpvArgument1, // void* in/out
void* lpvArgument2, // void* in/out
const(wchar)* szVersion, // LPCWSTR
void* pvReserved // void* in/out
);ccall((:CallFunctionShim, "MSCorEE.dll"), stdcall, Int32,
(Cwstring, Cstring, Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Ptr{Cvoid}),
szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
# szDllName : LPCWSTR -> Cwstring
# szFunctionName : LPCSTR -> Cstring
# lpvArgument1 : void* in/out -> Ptr{Cvoid}
# lpvArgument2 : void* in/out -> Ptr{Cvoid}
# szVersion : LPCWSTR -> Cwstring
# pvReserved : void* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CallFunctionShim(
const uint16_t* szDllName,
const char* szFunctionName,
void* lpvArgument1,
void* lpvArgument2,
const uint16_t* szVersion,
void* pvReserved);
]]
local mscoree = ffi.load("mscoree")
-- mscoree.CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
-- szDllName : LPCWSTR
-- szFunctionName : LPCSTR
-- lpvArgument1 : void* in/out
-- lpvArgument2 : void* in/out
-- szVersion : LPCWSTR
-- pvReserved : void* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MSCorEE.dll');
const CallFunctionShim = lib.func('__stdcall', 'CallFunctionShim', 'int32_t', ['str16', 'str', 'void *', 'void *', 'str16', 'void *']);
// CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
// szDllName : LPCWSTR -> 'str16'
// szFunctionName : LPCSTR -> 'str'
// lpvArgument1 : void* in/out -> 'void *'
// lpvArgument2 : void* in/out -> 'void *'
// szVersion : LPCWSTR -> 'str16'
// pvReserved : void* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MSCorEE.dll", {
CallFunctionShim: { parameters: ["buffer", "buffer", "pointer", "pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved)
// szDllName : LPCWSTR -> "buffer"
// szFunctionName : LPCSTR -> "buffer"
// lpvArgument1 : void* in/out -> "pointer"
// lpvArgument2 : void* in/out -> "pointer"
// szVersion : LPCWSTR -> "buffer"
// pvReserved : void* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CallFunctionShim(
const uint16_t* szDllName,
const char* szFunctionName,
void* lpvArgument1,
void* lpvArgument2,
const uint16_t* szVersion,
void* pvReserved);
C, "MSCorEE.dll");
// $ffi->CallFunctionShim(szDllName, szFunctionName, lpvArgument1, lpvArgument2, szVersion, pvReserved);
// szDllName : LPCWSTR
// szFunctionName : LPCSTR
// lpvArgument1 : void* in/out
// lpvArgument2 : void* in/out
// szVersion : LPCWSTR
// pvReserved : void* 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 Mscoree extends StdCallLibrary {
Mscoree INSTANCE = Native.load("mscoree", Mscoree.class);
int CallFunctionShim(
WString szDllName, // LPCWSTR
String szFunctionName, // LPCSTR
Pointer lpvArgument1, // void* in/out
Pointer lpvArgument2, // void* in/out
WString szVersion, // LPCWSTR
Pointer pvReserved // void* in/out
);
}@[Link("mscoree")]
lib LibMSCorEE
fun CallFunctionShim = CallFunctionShim(
szDllName : UInt16*, # LPCWSTR
szFunctionName : UInt8*, # LPCSTR
lpvArgument1 : Void*, # void* in/out
lpvArgument2 : Void*, # void* in/out
szVersion : UInt16*, # LPCWSTR
pvReserved : Void* # void* 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 CallFunctionShimNative = Int32 Function(Pointer<Utf16>, Pointer<Utf8>, Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
typedef CallFunctionShimDart = int Function(Pointer<Utf16>, Pointer<Utf8>, Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
final CallFunctionShim = DynamicLibrary.open('MSCorEE.dll')
.lookupFunction<CallFunctionShimNative, CallFunctionShimDart>('CallFunctionShim');
// szDllName : LPCWSTR -> Pointer<Utf16>
// szFunctionName : LPCSTR -> Pointer<Utf8>
// lpvArgument1 : void* in/out -> Pointer<Void>
// lpvArgument2 : void* in/out -> Pointer<Void>
// szVersion : LPCWSTR -> Pointer<Utf16>
// pvReserved : void* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CallFunctionShim(
szDllName: PWideChar; // LPCWSTR
szFunctionName: PAnsiChar; // LPCSTR
lpvArgument1: Pointer; // void* in/out
lpvArgument2: Pointer; // void* in/out
szVersion: PWideChar; // LPCWSTR
pvReserved: Pointer // void* in/out
): Integer; stdcall;
external 'MSCorEE.dll' name 'CallFunctionShim';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CallFunctionShim"
c_CallFunctionShim :: CWString -> CString -> Ptr () -> Ptr () -> CWString -> Ptr () -> IO Int32
-- szDllName : LPCWSTR -> CWString
-- szFunctionName : LPCSTR -> CString
-- lpvArgument1 : void* in/out -> Ptr ()
-- lpvArgument2 : void* in/out -> Ptr ()
-- szVersion : LPCWSTR -> CWString
-- pvReserved : void* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let callfunctionshim =
foreign "CallFunctionShim"
((ptr uint16_t) @-> string @-> (ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* szDllName : LPCWSTR -> (ptr uint16_t) *)
(* szFunctionName : LPCSTR -> string *)
(* lpvArgument1 : void* in/out -> (ptr void) *)
(* lpvArgument2 : void* in/out -> (ptr void) *)
(* szVersion : LPCWSTR -> (ptr uint16_t) *)
(* pvReserved : void* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mscoree (t "MSCorEE.dll"))
(cffi:use-foreign-library mscoree)
(cffi:defcfun ("CallFunctionShim" call-function-shim :convention :stdcall) :int32
(sz-dll-name (:string :encoding :utf-16le)) ; LPCWSTR
(sz-function-name :string) ; LPCSTR
(lpv-argument1 :pointer) ; void* in/out
(lpv-argument2 :pointer) ; void* in/out
(sz-version (:string :encoding :utf-16le)) ; LPCWSTR
(pv-reserved :pointer)) ; void* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CallFunctionShim = Win32::API::More->new('MSCorEE',
'int CallFunctionShim(LPCWSTR szDllName, LPCSTR szFunctionName, LPVOID lpvArgument1, LPVOID lpvArgument2, LPCWSTR szVersion, LPVOID pvReserved)');
# my $ret = $CallFunctionShim->Call($szDllName, $szFunctionName, $lpvArgument1, $lpvArgument2, $szVersion, $pvReserved);
# szDllName : LPCWSTR -> LPCWSTR
# szFunctionName : LPCSTR -> LPCSTR
# lpvArgument1 : void* in/out -> LPVOID
# lpvArgument2 : void* in/out -> LPVOID
# szVersion : LPCWSTR -> LPCWSTR
# pvReserved : void* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。