ホーム › System.ClrHosting › RunDll32ShimW
RunDll32ShimW
関数rundll32経由でマネージドエントリポイントを起動するシムを実行する。
シグネチャ
// MSCorEE.dll
#include <windows.h>
HRESULT RunDll32ShimW(
HWND hwnd,
HINSTANCE hinst,
LPCWSTR lpszCmdLine,
INT nCmdShow
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | in | 呼び出し元ウィンドウのハンドル。rundll32 互換のため指定する。 |
| hinst | HINSTANCE | in | 呼び出し元インスタンスのハンドル。rundll32 互換のため指定する。 |
| lpszCmdLine | LPCWSTR | in | 実行するコマンドラインを示す文字列。Unicode 文字列で指定する。 |
| nCmdShow | INT | in | ウィンドウ表示状態を示す値。SW_SHOW 等を指定する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// MSCorEE.dll
#include <windows.h>
HRESULT RunDll32ShimW(
HWND hwnd,
HINSTANCE hinst,
LPCWSTR lpszCmdLine,
INT nCmdShow
);[DllImport("MSCorEE.dll", ExactSpelling = true)]
static extern int RunDll32ShimW(
IntPtr hwnd, // HWND
IntPtr hinst, // HINSTANCE
[MarshalAs(UnmanagedType.LPWStr)] string lpszCmdLine, // LPCWSTR
int nCmdShow // INT
);<DllImport("MSCorEE.dll", ExactSpelling:=True)>
Public Shared Function RunDll32ShimW(
hwnd As IntPtr, ' HWND
hinst As IntPtr, ' HINSTANCE
<MarshalAs(UnmanagedType.LPWStr)> lpszCmdLine As String, ' LPCWSTR
nCmdShow As Integer ' INT
) As Integer
End Function' hwnd : HWND
' hinst : HINSTANCE
' lpszCmdLine : LPCWSTR
' nCmdShow : INT
Declare PtrSafe Function RunDll32ShimW Lib "mscoree" ( _
ByVal hwnd As LongPtr, _
ByVal hinst As LongPtr, _
ByVal lpszCmdLine As LongPtr, _
ByVal nCmdShow As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RunDll32ShimW = ctypes.windll.mscoree.RunDll32ShimW
RunDll32ShimW.restype = ctypes.c_int
RunDll32ShimW.argtypes = [
wintypes.HANDLE, # hwnd : HWND
wintypes.HANDLE, # hinst : HINSTANCE
wintypes.LPCWSTR, # lpszCmdLine : LPCWSTR
ctypes.c_int, # nCmdShow : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MSCorEE.dll')
RunDll32ShimW = Fiddle::Function.new(
lib['RunDll32ShimW'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND
Fiddle::TYPE_VOIDP, # hinst : HINSTANCE
Fiddle::TYPE_VOIDP, # lpszCmdLine : LPCWSTR
Fiddle::TYPE_INT, # nCmdShow : INT
],
Fiddle::TYPE_INT)#[link(name = "mscoree")]
extern "system" {
fn RunDll32ShimW(
hwnd: *mut core::ffi::c_void, // HWND
hinst: *mut core::ffi::c_void, // HINSTANCE
lpszCmdLine: *const u16, // LPCWSTR
nCmdShow: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MSCorEE.dll")]
public static extern int RunDll32ShimW(IntPtr hwnd, IntPtr hinst, [MarshalAs(UnmanagedType.LPWStr)] string lpszCmdLine, int nCmdShow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSCorEE_RunDll32ShimW' -Namespace Win32 -PassThru
# $api::RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)#uselib "MSCorEE.dll"
#func global RunDll32ShimW "RunDll32ShimW" sptr, sptr, sptr, sptr
; RunDll32ShimW hwnd, hinst, lpszCmdLine, nCmdShow ; 戻り値は stat
; hwnd : HWND -> "sptr"
; hinst : HINSTANCE -> "sptr"
; lpszCmdLine : LPCWSTR -> "sptr"
; nCmdShow : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "MSCorEE.dll"
#cfunc global RunDll32ShimW "RunDll32ShimW" sptr, sptr, wstr, int
; res = RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
; hwnd : HWND -> "sptr"
; hinst : HINSTANCE -> "sptr"
; lpszCmdLine : LPCWSTR -> "wstr"
; nCmdShow : INT -> "int"; HRESULT RunDll32ShimW(HWND hwnd, HINSTANCE hinst, LPCWSTR lpszCmdLine, INT nCmdShow)
#uselib "MSCorEE.dll"
#cfunc global RunDll32ShimW "RunDll32ShimW" intptr, intptr, wstr, int
; res = RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
; hwnd : HWND -> "intptr"
; hinst : HINSTANCE -> "intptr"
; lpszCmdLine : LPCWSTR -> "wstr"
; nCmdShow : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mscoree = windows.NewLazySystemDLL("MSCorEE.dll")
procRunDll32ShimW = mscoree.NewProc("RunDll32ShimW")
)
// hwnd (HWND), hinst (HINSTANCE), lpszCmdLine (LPCWSTR), nCmdShow (INT)
r1, _, err := procRunDll32ShimW.Call(
uintptr(hwnd),
uintptr(hinst),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszCmdLine))),
uintptr(nCmdShow),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction RunDll32ShimW(
hwnd: THandle; // HWND
hinst: THandle; // HINSTANCE
lpszCmdLine: PWideChar; // LPCWSTR
nCmdShow: Integer // INT
): Integer; stdcall;
external 'MSCorEE.dll' name 'RunDll32ShimW';result := DllCall("MSCorEE\RunDll32ShimW"
, "Ptr", hwnd ; HWND
, "Ptr", hinst ; HINSTANCE
, "WStr", lpszCmdLine ; LPCWSTR
, "Int", nCmdShow ; INT
, "Int") ; return: HRESULT●RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow) = DLL("MSCorEE.dll", "int RunDll32ShimW(void*, void*, char*, int)")
# 呼び出し: RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
# hwnd : HWND -> "void*"
# hinst : HINSTANCE -> "void*"
# lpszCmdLine : LPCWSTR -> "char*"
# nCmdShow : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mscoree" fn RunDll32ShimW(
hwnd: ?*anyopaque, // HWND
hinst: ?*anyopaque, // HINSTANCE
lpszCmdLine: [*c]const u16, // LPCWSTR
nCmdShow: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc RunDll32ShimW(
hwnd: pointer, # HWND
hinst: pointer, # HINSTANCE
lpszCmdLine: WideCString, # LPCWSTR
nCmdShow: int32 # INT
): int32 {.importc: "RunDll32ShimW", stdcall, dynlib: "MSCorEE.dll".}pragma(lib, "mscoree");
extern(Windows)
int RunDll32ShimW(
void* hwnd, // HWND
void* hinst, // HINSTANCE
const(wchar)* lpszCmdLine, // LPCWSTR
int nCmdShow // INT
);ccall((:RunDll32ShimW, "MSCorEE.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Int32),
hwnd, hinst, lpszCmdLine, nCmdShow)
# hwnd : HWND -> Ptr{Cvoid}
# hinst : HINSTANCE -> Ptr{Cvoid}
# lpszCmdLine : LPCWSTR -> Cwstring
# nCmdShow : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t RunDll32ShimW(
void* hwnd,
void* hinst,
const uint16_t* lpszCmdLine,
int32_t nCmdShow);
]]
local mscoree = ffi.load("mscoree")
-- mscoree.RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
-- hwnd : HWND
-- hinst : HINSTANCE
-- lpszCmdLine : LPCWSTR
-- nCmdShow : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MSCorEE.dll');
const RunDll32ShimW = lib.func('__stdcall', 'RunDll32ShimW', 'int32_t', ['void *', 'void *', 'str16', 'int32_t']);
// RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
// hwnd : HWND -> 'void *'
// hinst : HINSTANCE -> 'void *'
// lpszCmdLine : LPCWSTR -> 'str16'
// nCmdShow : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MSCorEE.dll", {
RunDll32ShimW: { parameters: ["pointer", "pointer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow)
// hwnd : HWND -> "pointer"
// hinst : HINSTANCE -> "pointer"
// lpszCmdLine : LPCWSTR -> "buffer"
// nCmdShow : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RunDll32ShimW(
void* hwnd,
void* hinst,
const uint16_t* lpszCmdLine,
int32_t nCmdShow);
C, "MSCorEE.dll");
// $ffi->RunDll32ShimW(hwnd, hinst, lpszCmdLine, nCmdShow);
// hwnd : HWND
// hinst : HINSTANCE
// lpszCmdLine : LPCWSTR
// nCmdShow : INT
// 構造体/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 RunDll32ShimW(
Pointer hwnd, // HWND
Pointer hinst, // HINSTANCE
WString lpszCmdLine, // LPCWSTR
int nCmdShow // INT
);
}@[Link("mscoree")]
lib LibMSCorEE
fun RunDll32ShimW = RunDll32ShimW(
hwnd : Void*, # HWND
hinst : Void*, # HINSTANCE
lpszCmdLine : UInt16*, # LPCWSTR
nCmdShow : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RunDll32ShimWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Int32);
typedef RunDll32ShimWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int);
final RunDll32ShimW = DynamicLibrary.open('MSCorEE.dll')
.lookupFunction<RunDll32ShimWNative, RunDll32ShimWDart>('RunDll32ShimW');
// hwnd : HWND -> Pointer<Void>
// hinst : HINSTANCE -> Pointer<Void>
// lpszCmdLine : LPCWSTR -> Pointer<Utf16>
// nCmdShow : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RunDll32ShimW(
hwnd: THandle; // HWND
hinst: THandle; // HINSTANCE
lpszCmdLine: PWideChar; // LPCWSTR
nCmdShow: Integer // INT
): Integer; stdcall;
external 'MSCorEE.dll' name 'RunDll32ShimW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RunDll32ShimW"
c_RunDll32ShimW :: Ptr () -> Ptr () -> CWString -> Int32 -> IO Int32
-- hwnd : HWND -> Ptr ()
-- hinst : HINSTANCE -> Ptr ()
-- lpszCmdLine : LPCWSTR -> CWString
-- nCmdShow : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rundll32shimw =
foreign "RunDll32ShimW"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* hinst : HINSTANCE -> (ptr void) *)
(* lpszCmdLine : LPCWSTR -> (ptr uint16_t) *)
(* nCmdShow : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mscoree (t "MSCorEE.dll"))
(cffi:use-foreign-library mscoree)
(cffi:defcfun ("RunDll32ShimW" run-dll32-shim-w :convention :stdcall) :int32
(hwnd :pointer) ; HWND
(hinst :pointer) ; HINSTANCE
(lpsz-cmd-line (:string :encoding :utf-16le)) ; LPCWSTR
(n-cmd-show :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RunDll32ShimW = Win32::API::More->new('MSCorEE',
'int RunDll32ShimW(HANDLE hwnd, HANDLE hinst, LPCWSTR lpszCmdLine, int nCmdShow)');
# my $ret = $RunDll32ShimW->Call($hwnd, $hinst, $lpszCmdLine, $nCmdShow);
# hwnd : HWND -> HANDLE
# hinst : HINSTANCE -> HANDLE
# lpszCmdLine : LPCWSTR -> LPCWSTR
# nCmdShow : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。