summaryrefslogtreecommitdiff
path: root/Lib/com/std_wstring.i
blob: 5452dc2f70f31676db305aad61d1f4bf54a9ba76 (plain)
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
/* -----------------------------------------------------------------------------
 * std_wstring.swg
 *
 * COM typemaps for std::wstring and const std::wstring&
 * ----------------------------------------------------------------------------- */

%{
#include <string>
#include <wchar.h>
%}

namespace std {

%naturalvar wstring;
class wstring;

%typemap(ctype) wstring, const wstring& "WCHAR *"
%typemap(comtype) wstring, const wstring& "BSTR"

%typemap(in) wstring {
  if ($input) {
    $1.assign($input);
  }
}

%typemap(in) const wstring & ($*1_ltype temp)
%{
  if ($input)
    temp.assign($input);
  $1 = &temp;
%}

%typemap(out) wstring %{
  {
    int SWIG_len = $1.size() + 1;
    WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR));
    /* First 4 bytes contain length in bytes */
    *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR);
    wcsncpy(SWIG_res + 2, $1.c_str(), SWIG_len);
    $result = SWIG_res + 2;
  }
%}

%typemap(out) const wstring & %{
  {
    int SWIG_len = (*$1).size() + 1;
    WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR));
    /* First 4 bytes contain length in bytes */
    *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR);
    wcsncpy(SWIG_res + 2, (*$1).c_str(), SWIG_len);
    $result = SWIG_res + 2;
  }
%}


}