質問編集履歴
2
疑問点の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
- getメソッド利用
|
6
6
|
``` cpp
|
7
|
-
// 動かない
|
7
|
+
// 動かない 11/20 訂正
|
8
8
|
std::unique_ptr<wchar_t> sjis_to_utf16(const std::string str) {
|
9
9
|
const int wchar_len = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
|
10
10
|
std::unique_ptr<wchar_t> utf16_str(new wchar_t(wchar_len));
|
@@ -34,4 +34,20 @@
|
|
34
34
|
std::unique_ptr<wchar_t> utf16_str(p_utf16_str);
|
35
35
|
return std::move(utf16_str);
|
36
36
|
}
|
37
|
-
```
|
37
|
+
```
|
38
|
+
|
39
|
+
- 追記 11/20
|
40
|
+
自作した関数に.getメソッドで渡すと、正常に動作しているようでした。
|
41
|
+
`MultiByteToWideChar()`側に問題があるのかもしれません。
|
42
|
+
型の違いが原因である気がしてきました…
|
43
|
+
[MultiByteToWideCharのリファレンス](https://msdn.microsoft.com/ja-jp/library/cc448053.aspx)
|
44
|
+
|
45
|
+
```
|
46
|
+
int MultiByteToWideChar(
|
47
|
+
UINT CodePage, // コードページ
|
48
|
+
DWORD dwFlags, // 文字の種類を指定するフラグ
|
49
|
+
LPCSTR lpMultiByteStr, // マップ元文字列のアドレス
|
50
|
+
int cchMultiByte, // マップ元文字列のバイト数
|
51
|
+
LPWSTR lpWideCharStr, // マップ先ワイド文字列を入れるバッファのアドレス
|
52
|
+
int cchWideChar // バッファのサイズ
|
53
|
+
);```
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
// 動かない
|
8
8
|
std::unique_ptr<wchar_t> sjis_to_utf16(const std::string str) {
|
9
9
|
const int wchar_len = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
|
10
|
-
std::unique_ptr<wchar_t> utf16_str(
|
10
|
+
std::unique_ptr<wchar_t> utf16_str(new wchar_t(wchar_len));
|
11
|
-
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1,
|
11
|
+
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, utf16_str.get(), wchar_len);
|
12
12
|
return std::move(utf16_str);
|
13
13
|
}
|
14
14
|
```
|