/tags/rel-1.3.35/Lib/csharp/wchar.i
Swig | 105 lines | 74 code | 18 blank | 13 comment | 0 complexity | 9ab79e777d4bc5004adebdef98b4f6f6 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1/* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4 *
5 * wchar.i
6 *
7 * Typemaps for the wchar_t type
8 * These are mapped to a C# String and are passed around by value.
9 *
10 * Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER
11 *
12 * ----------------------------------------------------------------------------- */
13
14#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)
15#if !defined(SWIG_CSHARP_WSTRING_HELPER_)
16#define SWIG_CSHARP_WSTRING_HELPER_
17%insert(runtime) %{
18/* Callback for returning strings to C# without leaking memory */
19typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
20static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
21%}
22
23%pragma(csharp) imclasscode=%{
24 protected class SWIGWStringHelper {
25
26 public delegate string SWIGWStringDelegate(IntPtr message);
27 static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);
28
29 [DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]
30 public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);
31
32 static string CreateWString([MarshalAs(UnmanagedType.LPWStr)]IntPtr cString) {
33 return System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
34 }
35
36 static SWIGWStringHelper() {
37 SWIGRegisterWStringCallback_$module(wstringDelegate);
38 }
39 }
40
41 static protected SWIGWStringHelper swigWStringHelper = new SWIGWStringHelper();
42%}
43
44%insert(runtime) %{
45#ifdef __cplusplus
46extern "C"
47#endif
48SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {
49 SWIG_csharp_wstring_callback = callback;
50}
51%}
52#endif // SWIG_CSHARP_WSTRING_HELPER_
53#endif // SWIG_CSHARP_NO_WSTRING_HELPER
54
55
56// wchar_t
57%typemap(ctype) wchar_t "wchar_t"
58%typemap(imtype) wchar_t "char"
59%typemap(cstype) wchar_t "char"
60
61%typemap(csin) wchar_t "$csinput"
62%typemap(csout, excode=SWIGEXCODE) wchar_t {
63 char ret = $imcall;$excode
64 return ret;
65 }
66%typemap(csvarin, excode=SWIGEXCODE2) wchar_t %{
67 set {
68 $imcall;$excode
69 } %}
70%typemap(csvarout, excode=SWIGEXCODE2) wchar_t %{
71 get {
72 char ret = $imcall;$excode
73 return ret;
74 } %}
75
76%typemap(in) wchar_t %{ $1 = ($1_ltype)$input; %}
77%typemap(out) wchar_t %{ $result = (wchar_t)$1; %}
78
79%typemap(typecheck) wchar_t = char;
80
81// wchar_t *
82%typemap(ctype) wchar_t * "wchar_t *"
83%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="IntPtr" ) wchar_t * "string"
84%typemap(cstype) wchar_t * "string"
85
86%typemap(csin) wchar_t * "$csinput"
87%typemap(csout, excode=SWIGEXCODE) wchar_t * {
88 string ret = System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
89 return ret;
90 }
91%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
92 set {
93 $imcall;$excode
94 } %}
95%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
96 get {
97 string ret = $imcall;$excode
98 return ret;
99 } %}
100
101%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}
102%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}
103
104%typemap(typecheck) wchar_t * = char *;
105