Win32 API 日本語リファレンス
ホームSystem.ClrHosting › CallFunctionShim

CallFunctionShim

関数
指定したDLLの関数をバージョン指定で呼び出すシムを実行する。
DLLMSCorEE.dll呼出規約winapi

シグネチャ

// MSCorEE.dll
#include <windows.h>

HRESULT CallFunctionShim(
    LPCWSTR szDllName,
    LPCSTR szFunctionName,
    void* lpvArgument1,
    void* lpvArgument2,
    LPCWSTR szVersion,
    void* pvReserved
);

パラメーター

名前方向
szDllNameLPCWSTRin
szFunctionNameLPCSTRin
lpvArgument1void*inout
lpvArgument2void*inout
szVersionLPCWSTRin
pvReservedvoid*inout

戻り値の型: 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   // HRESULT
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';
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)。