static void Main() { Console.WriteLine("Adding and calling a normal C++ callback"); Console.WriteLine("----------------------------------------"); Caller caller = new Caller(); using (Callback callback = new Callback()) { caller.setCallback(callback); caller.call(); caller.resetCallback(); } Console.WriteLine(); Console.WriteLine("Adding and calling a C# callback"); Console.WriteLine("------------------------------------"); using (Callback callback = new CSharpCallback()) { caller.setCallback(callback); caller.call(); caller.resetCallback(); } Console.WriteLine(); Console.WriteLine("C# exit"); }
private void Foo() { unsafe { ulong nwid = 0xabfd31bd47bef75e; int err; _callback = new CSharpCallback(MyCallback); //var functionPointerForDelegate = Marshal.GetFunctionPointerForDelegate(_callback); var currentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var foo = zts_allow_local_conf(1); if ((err = zts_start(currentDirectory, _callback, 9994)) == 1) { throw new Exception($"Failed to start/join network [{nwid:X}]"); } Debug.WriteLine(err); } }
public static extern int zts_start(string path, CSharpCallback callback, int port);
// Use this for initialization void Start() { CSharpCallback.CallChainFromManaged(3, 5); }