1
Imports System.Runtime.InteropServices Module Module1
_ Public Function LoadLibraryA( _
ByVal DllName As String _ ) As Integer End Function
_ Public Function FreeLibrary( _ ByVal hModule As Integer _ ) As Integer End Function
_ Public Function GetProcAddress( _ ByVal hModule As Integer, _
ByVal lpProcName As String _ ) As Integer End Function
_ Public Function GetDesktopWindow() As Integer End Function Delegate Sub PrintUIEntryW( _ ByVal hwnd As Int32, _ ByVal hinst As Int32, _
ByVal text As String, _ ByVal nCmdShow As Int32) Sub Main(ByVal Argv As String()) If Argv.Length <> 1 Then Exit Sub End If Dim hModule As Integer = LoadLibraryA("printui.dll") ' ******************************************************** ' 実行 ' ******************************************************** Dim ptr As IntPtr ptr = GetProcAddress(hModule, "PrintUIEntryW") If ptr <> IntPtr.Zero Then Dim func1 As PrintUIEntryW = _ Marshal.GetDelegateForFunctionPointer(ptr, _ GetType(PrintUIEntryW) _ ) Call func1(GetDesktopWindow(), hModule, _ "/y /n """ & Argv(0) & """", 5) End If End Sub End Module
1
using System; using System.Runtime.InteropServices; class Module1 { [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int LoadLibraryA([MarshalAs(UnmanagedType.LPStr)] string DllName); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int FreeLibrary(int hModule); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int GetProcAddress(int hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int GetDesktopWindow(); public delegate void PrintUIEntryW( Int32 hwnd, Int32 hinst, [MarshalAs(UnmanagedType.LPWStr)] string text, Int32 nCmdShow); public static void Main(string[] Argv) { if (Argv.Length != 1) { return; } int hModule = LoadLibraryA("printui.dll"); // ******************************************************** // 実行 // ******************************************************** IntPtr ptr; ptr = (IntPtr)GetProcAddress(hModule, "PrintUIEntryW"); if (ptr != IntPtr.Zero) { PrintUIEntryW func1 = (PrintUIEntryW)Marshal.GetDelegateForFunctionPointer(ptr, typeof(PrintUIEntryW)); func1(GetDesktopWindow(), hModule, "/y /n \"" + Argv[0] + "\"", 5); } } }