calling native dll

Mar 3, 2014 at 4:43 PM
hi, how can i use native functions from user32.dll or something else in clearscript?
Coordinator
Mar 4, 2014 at 1:43 PM
Hi furesoft,

You can expose a .NET type with a P/Invoke method and invoke it from script. For example:
public static class Native
{
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int MessageBox(IntPtr hWnd, string text, string caption, int options);
}
and then
engine.AddHostType("Native", typeof(Native));
engine.AddHostType("IntPtr", typeof(IntPtr));
engine.Execute("Native.MessageBox(IntPtr.Zero, 'Hello!', 'Greetings', 0)");
Good luck!