Rank: Advanced Member
Groups: Translators, Moderators, Approved Joined: 4/6/2020(UTC) Posts: 79 Thanks: 1 times Was thanked: 21 time(s) in 21 post(s)
|
First, place this in load script. Code:function MethodFromNativeDll (DllPath, EntryName, RtnT, ParmT) {
var asmName = new clr.System.Reflection.AssemblyName();
asmName.Name = "NativeDll";
var asmBuilder =
clr.System.AppDomain.CurrentDomain.DefineDynamicAssembly(
asmName, clr.System.Reflection.Emit.AssemblyBuilderAccess.Run);
var modBuilder =
asmBuilder.DefineDynamicModule("NativeDll");
var methdBuilder =
modBuilder.DefinePInvokeMethod(EntryName, DllPath,
clr.System.Enum.Parse(clr.System.Reflection.MethodAttributes.Final.GetType(),
'Public, Static, PinvokeImpl'),
clr.System.Reflection.CallingConventions.Standard, RtnT, ParmT,
clr.System.Runtime.InteropServices.CallingConvention.Winapi,
clr.System.Runtime.InteropServices.CharSet.Ansi);
methdBuilder.SetImplementationFlags(
clr.System.Enum.Parse(clr.System.Reflection.MethodImplAttributes.IL.GetType(),
methdBuilder.GetMethodImplementationFlags().ToString() + ", PreserveSig"));
modBuilder.CreateGlobalFunctions();
mthdInfo = modBuilder.GetMethod(EntryName);
return mthdInfo;
}
Example code: Code://Type for return value.
var RtnT = clr.System.Type.GetType("System.Int32");
//Type array for param types.
var ParmT = host.newArr(clr.System.Type, 2);
ParmT[0] = clr.System.Type.GetType("System.IntPtr");
ParmT[1] = clr.System.Type.GetType("System.Int32&");
//For ByRef vars, append a & after the type name.
//Object array for params.
var Parm = host.newArr(clr.System.Object, 2);
Parm[0] = sp.DesktopWindow().HWnd;
Parm[1] = 0;
//Get method
var Mthd = MethodFromNativeDll("user32.dll", "GetWindowThreadProcessId", RtnT, ParmT);
//Invoke method.
var v = Mthd.Invoke(null, Parm);
sp.MessageBox(Parm[1], v);
Edited by user Tuesday, May 5, 2020 6:11:03 AM(UTC)
| Reason: Not specified
|
1 user thanked liuxilu for this useful post.
|
|