diff options
Diffstat (limited to 'src/bluetooth/qbluetoothutils_winrt.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothutils_winrt.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothutils_winrt.cpp b/src/bluetooth/qbluetoothutils_winrt.cpp index 1d44221b..de4355c6 100644 --- a/src/bluetooth/qbluetoothutils_winrt.cpp +++ b/src/bluetooth/qbluetoothutils_winrt.cpp @@ -42,12 +42,15 @@ #include <QtCore/qfunctions_winrt.h> +#include <robuffer.h> #include <wrl.h> #include <windows.foundation.metadata.h> +#include <windows.storage.streams.h> using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; using namespace ABI::Windows::Foundation::Metadata; +using namespace ABI::Windows::Storage::Streams; QT_BEGIN_NAMESPACE @@ -76,4 +79,26 @@ bool supportsNewLEApi() return apiPresent; } +QByteArray byteArrayFromBuffer(const ComPtr<NativeBuffer> &buffer, bool isWCharString) +{ + if (!buffer) { + qErrnoWarning("nullptr passed to byteArrayFromBuffer"); + return QByteArray(); + } + ComPtr<Windows::Storage::Streams::IBufferByteAccess> byteAccess; + HRESULT hr = buffer.As(&byteAccess); + RETURN_IF_FAILED("Could not cast buffer", return QByteArray()) + char *data; + hr = byteAccess->Buffer(reinterpret_cast<byte **>(&data)); + RETURN_IF_FAILED("Could not obtain buffer data", return QByteArray()) + UINT32 size; + hr = buffer->get_Length(&size); + RETURN_IF_FAILED("Could not obtain buffer size", return QByteArray()) + if (isWCharString) { + QString valueString = QString::fromUtf16(reinterpret_cast<ushort *>(data)).left(size / 2); + return valueString.toUtf8(); + } + return QByteArray(data, qint32(size)); +} + QT_END_NAMESPACE |