コード例 #1
0
ファイル: WinrtFromDesktop.cpp プロジェクト: kiewic/Projects
HRESULT TestJson()
{
    HRESULT hr;

    HSTRING className;
    IfFailedReturn(WindowsCreateString(
        RuntimeClass_Windows_Data_Json_JsonObject,
        wcslen(RuntimeClass_Windows_Data_Json_JsonObject),
        &className));

    IInspectable* inspectable;
    IfFailedReturn(RoActivateInstance(className, &inspectable));

    ULONG iidCount;
    IID* iids;
    IfFailedReturn(inspectable->GetIids(&iidCount, &iids));

    wprintf(L"Iids: %d\r\n", iidCount);

    IJsonValue* jsonValue;
    IfFailedReturn(inspectable->QueryInterface(__uuidof(jsonValue), reinterpret_cast<void**>(&jsonValue)));

    HSTRING jsonString;
    IfFailedReturn(jsonValue->Stringify(&jsonString));

    // TODO: Confirm that length parameter is required. I heard it is needed beacuase it is not guaranteed that the
    // PCWSTR will end on null character.
    UINT32 length;
    const wchar_t* rawJsonString;
    rawJsonString = WindowsGetStringRawBuffer(jsonString, &length);
    wprintf(L"Stringify: %s \r\nlength: %d\r\n", rawJsonString, length);

    IfFailedReturn(WindowsDeleteString(className));

    IfFailedReturn(WindowsDeleteString(jsonString));

    return S_OK;
}