-
Notifications
You must be signed in to change notification settings - Fork 0
/
DllExportAttribute.cs
76 lines (66 loc) · 2.42 KB
/
DllExportAttribute.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DllExport
{
/// <summary>
/// Attribute added to a static C# method to export it
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class DllExportAttribute : Attribute
{
private string m_exportName;
private CallingConvention m_callingConvention;
/// <summary>
/// Constructor 1
/// </summary>
/// <param name="exportName"></param>
public DllExportAttribute(string exportName)
: this(exportName, System.Runtime.InteropServices.CallingConvention.StdCall)
{
}
/// <summary>
/// Constructor 2
/// </summary>
/// <param name="exportName"></param>
/// <param name="callingConvention"></param>
public DllExportAttribute(string exportName, CallingConvention callingConvention)
{
m_exportName = exportName;
m_callingConvention = callingConvention;
}
/// <summary>
/// Get the export name, or null to use the method name
/// </summary>
public string ExportName
{
get { return m_exportName; }
}
/// <summary>
/// Get the calling convention
/// </summary>
public string CallingConvention
{
get
{
switch (m_callingConvention)
{
case System.Runtime.InteropServices.CallingConvention.Cdecl:
return typeof(CallConvCdecl).FullName;
case System.Runtime.InteropServices.CallingConvention.FastCall:
return typeof(CallConvFastcall).FullName;
case System.Runtime.InteropServices.CallingConvention.StdCall:
return typeof(CallConvStdcall).FullName;
case System.Runtime.InteropServices.CallingConvention.ThisCall:
return typeof(CallConvThiscall).FullName;
case System.Runtime.InteropServices.CallingConvention.Winapi:
return typeof(CallConvStdcall).FullName;
default:
return "";
}
}
}
}
}