-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrorCode.cs
More file actions
74 lines (61 loc) · 2.02 KB
/
Copy pathErrorCode.cs
File metadata and controls
74 lines (61 loc) · 2.02 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Tsunami.Core
{
using ErrorCodeHandle = HandleRef;
public class ErrorCode : IDisposable
{
#region PInvoke
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr ErrorCode_Create();
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr ErrorCode_Destroy(ErrorCodeHandle handle);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void ErrorCode_Message_Get(ErrorCodeHandle handle, StringBuilder str, int size);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern int ErrorCode_Value_Get(ErrorCodeHandle handle);
#endregion PInvoke
ErrorCodeHandle handle;
StringBuilder sb = new StringBuilder(256);
public ErrorCode()
{
IntPtr h = ErrorCode_Create();
handle = new HandleRef(this, h);
ErrorCode_Message_Get(handle, sb, sb.Capacity);
message = sb.ToString();
Value = ErrorCode_Value_Get(handle);
}
public ErrorCode(IntPtr h)
{
handle = new HandleRef(this, h);
ErrorCode_Message_Get(handle, sb, sb.Capacity);
message = sb.ToString();
Value = ErrorCode_Value_Get(handle);
}
private string message;
public string Message
{
get { return message; }
set { message = value; }
}
public int Value
{
get; set;
}
public void Dispose()
{
CleanUp();
GC.SuppressFinalize(this);
}
private void CleanUp()
{
ErrorCode_Destroy(handle);
handle = new HandleRef(this, IntPtr.Zero);
}
~ErrorCode()
{
CleanUp();
}
}
}