forked from DragonLi-Mi/JavaCallCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManaged.cs
More file actions
21 lines (15 loc) · 674 Bytes
/
Managed.cs
File metadata and controls
21 lines (15 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) Hubert Jarosz. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
using System;
using System.Runtime.InteropServices;
public class Managed {
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
unsafe delegate void myDelegate( IntPtr thisptr );
public static unsafe void runIt( IntPtr thisptr, IntPtr mem_fun ) {
Console.WriteLine("Here's C# code:");
myDelegate fun = (myDelegate) Marshal.GetDelegateForFunctionPointer( mem_fun, typeof(myDelegate) );
fun(thisptr); // first argument of member functions in C++ is "this", but it's hidden from us :-)
}
}