Windows Runtime Cpp 文字列操作 新しいページはコチラ
提供: yonewiki
(ページの作成:「Windows Runtime Cppへ戻る == '''概要''' == 文字列操作関数としてHSTRING型というのが提供されていて、WindowsRuntime関数では、この...」) |
(→生成 WindowsCreateString(関数)) |
||
| 10行: | 10行: | ||
| + | <syntaxhighlight lang="cpp" line start="1"> | ||
| + | #include <locale.h> | ||
| + | #include <wchar.h> | ||
| + | #include <stdio.h> | ||
| + | #include <crtdbg.h> | ||
| + | #include <roapi.h> | ||
| + | #include <winstring.h> | ||
| + | int main() { | ||
| + | HRESULT hr; | ||
| + | setlocale(LC_ALL, ""); | ||
| + | hr = RoInitialize(RO_INIT_TYPE::RO_INIT_MULTITHREADED); | ||
| + | |||
| + | if (FAILED(hr)) { | ||
| + | wprintf_s(L"初期化に失敗しました。\n"); | ||
| + | _CrtDbgBreak(); | ||
| + | return 0; | ||
| + | } | ||
| + | else { | ||
| + | wprintf_s(L"初期化に成功しました。\n"); | ||
| + | } | ||
| + | |||
| + | HSTRING hStr; | ||
| + | wchar_t cStr[] = L"ワイド文字列"; | ||
| + | size_t length = wcslen(cStr); | ||
| + | |||
| + | hr = WindowsCreateString(cStr, length, &hStr); | ||
| + | if (FAILED(hr)) { | ||
| + | wprintf_s(L"hString文字列の生成に失敗しました。\n"); | ||
| + | _CrtDbgBreak(); | ||
| + | return 0; | ||
| + | } | ||
| + | else { | ||
| + | wprintf_s(L"hString文字列の生成に成功しました。\n"); | ||
| + | } | ||
| + | |||
| + | wprintf_s(L"%s\n", WindowsGetStringRawBuffer(hStr, nullptr)); | ||
| + | |||
| + | hr = WindowsDeleteString(hStr); | ||
| + | if (FAILED(hr)) { | ||
| + | wprintf_s(L"hStr文字列の削除に失敗しました。\n"); | ||
| + | _CrtDbgBreak(); | ||
| + | return 0; | ||
| + | } | ||
| + | else { | ||
| + | wprintf_s(L"hStr文字列の削除に成功しました。\n"); | ||
| + | } | ||
| + | RoUninitialize(); | ||
| + | |||
| + | _wsystem(L"pause"); | ||
| + | |||
| + | return 0; | ||
| + | </syntaxhighlight> | ||
[[Windows Runtime Cpp]]へ戻る | [[Windows Runtime Cpp]]へ戻る | ||