-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassDelegateInStruct.cs
More file actions
31 lines (24 loc) · 842 Bytes
/
Copy pathPassDelegateInStruct.cs
File metadata and controls
31 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Text;
using JSIL.Runtime;
using System.Runtime.InteropServices;
public static unsafe class Program {
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Callback(int i);
[StructLayout(LayoutKind.Sequential)]
public struct CallbackStruct {
public ushort us;
public Callback callback;
}
[DllImport("common.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void CallFunctionInStruct (CallbackStruct s, int i);
public static void Main () {
Callback c = PrintSuccess;
var cHandle = GCHandle.Alloc(c);
var s = new CallbackStruct { us = 4, callback = c };
CallFunctionInStruct(s, 747);
}
public static void PrintSuccess (int i) {
Console.WriteLine("Success: {0}", i);
}
}