質問編集履歴

2

疑問点の追記

2016/11/20 03:45

投稿

wake_up_kemeko
wake_up_kemeko

スコア104

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ``` cpp
12
12
 
13
- // 動かない
13
+ // 動かない 11/20 訂正
14
14
 
15
15
  std::unique_ptr<wchar_t> sjis_to_utf16(const std::string str) {
16
16
 
@@ -71,3 +71,35 @@
71
71
  }
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ - 追記 11/20
78
+
79
+ 自作した関数に.getメソッドで渡すと、正常に動作しているようでした。
80
+
81
+ `MultiByteToWideChar()`側に問題があるのかもしれません。
82
+
83
+ 型の違いが原因である気がしてきました…
84
+
85
+ [MultiByteToWideCharのリファレンス](https://msdn.microsoft.com/ja-jp/library/cc448053.aspx)
86
+
87
+
88
+
89
+ ```
90
+
91
+ int MultiByteToWideChar(
92
+
93
+ UINT CodePage, // コードページ
94
+
95
+ DWORD dwFlags, // 文字の種類を指定するフラグ
96
+
97
+ LPCSTR lpMultiByteStr, // マップ元文字列のアドレス
98
+
99
+ int cchMultiByte, // マップ元文字列のバイト数
100
+
101
+ LPWSTR lpWideCharStr, // マップ先ワイド文字列を入れるバッファのアドレス
102
+
103
+ int cchWideChar // バッファのサイズ
104
+
105
+ );```

1

2016/11/20 03:45

投稿

wake_up_kemeko
wake_up_kemeko

スコア104

test CHANGED
File without changes
test CHANGED
@@ -16,9 +16,9 @@
16
16
 
17
17
  const int wchar_len = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
18
18
 
19
- std::unique_ptr<wchar_t> utf16_str(p_utf16_str);
19
+ std::unique_ptr<wchar_t> utf16_str(new wchar_t(wchar_len));
20
20
 
21
- ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, p_utf16_str, wchar_len);
21
+ ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, utf16_str.get(), wchar_len);
22
22
 
23
23
  return std::move(utf16_str);
24
24