-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJNINativeMethod.cs
More file actions
46 lines (38 loc) · 1.31 KB
/
JNINativeMethod.cs
File metadata and controls
46 lines (38 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Rodrigo Speller. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
namespace JNet.Runtime
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct JNINativeMethod
{
public string name;
public string signature;
public IntPtr fnPtr;
public static IntPtr MethodsToPtr(params JNINativeMethod[] methods)
{
var sz = Marshal.SizeOf<JNINativeMethod>();
var len = methods.Length;
var ptr = Marshal.AllocCoTaskMem(len * sz);
var current = ptr;
foreach (var method in methods)
{
Marshal.StructureToPtr(method, current, false);
current += sz;
}
return ptr;
}
public static void DestroyMethods(IntPtr methods, int nMethods)
{
var sz = Marshal.SizeOf<JNINativeMethod>();
var current = methods;
while (nMethods-- > 0)
{
Marshal.DestroyStructure<JNINativeMethod>(current);
current += sz;
}
Marshal.FreeCoTaskMem(methods);
}
}
}