-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathG2Product.cs
53 lines (45 loc) · 1.58 KB
/
G2Product.cs
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
47
48
49
50
51
52
using System;
using System.Text;
using System.Runtime.InteropServices;
using Senzing;
namespace Senzing
{
public class G2Product
{
[DllImport ("G2")]
static extern long G2Product_init(byte[] moduleName, byte[] iniParams, long verboseLogging);
public static void init(string moduleName, string iniParams, int verboseLogging) {
HandleError(G2Product_init(Encoding.UTF8.GetBytes(moduleName),Encoding.UTF8.GetBytes(iniParams), verboseLogging));
}
[DllImport ("G2")]
static extern long G2Product_destroy();
public static void destroy() {
HandleError(G2Product_destroy());
}
[DllImport ("G2")]
static extern IntPtr G2Product_version();
public static string version() {
return Util.UTF8toString(G2Product_version());
}
[DllImport ("G2")]
static extern IntPtr G2Product_license();
public static string license() {
return Util.UTF8toString(G2Product_license());
}
[DllImport ("G2")]
static extern long G2Product_getLastException([MarshalAs(UnmanagedType.LPArray)] byte[] buf, long length);
[DllImport ("G2")]
static extern long G2Product_getLastExceptionCode();
static void HandleError(long retCode)
{
if (retCode == 0)
return;
long errorCode = G2Product_getLastExceptionCode();
byte[] buf = new byte[4096];
if (G2Product_getLastException(buf, buf.Length) != 0)
G2Exception.HandleError(errorCode, System.Text.Encoding.UTF8.GetString(buf));
else
G2Exception.HandleError(errorCode, "Failed to return error message");
}
}
}