Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
windows.h
Go to the documentation of this file.
1// License: Apache 2.0. See LICENSE file in root directory.
2// Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3
4#pragma once
5
6#include <sstream>
7
8#ifdef WIN32
9#include <Windows.h>
10
11namespace utilities {
12namespace string {
13namespace windows {
14
15
16inline std::string win_to_utf( const WCHAR * s, int wlen = -1 )
17{
18 auto len = WideCharToMultiByte( CP_UTF8, 0, s, wlen, nullptr, 0, nullptr, nullptr );
19 if( len == 0 )
20 {
21 std::ostringstream ss;
22 ss << "WideCharToMultiByte(...) returned 0 and GetLastError() is " << GetLastError();
23 throw std::runtime_error( ss.str() );
24 }
25
26 std::string buffer;
27 buffer.resize( len - 1 ); // len includes the \0
28 len = WideCharToMultiByte( CP_UTF8, 0, s, wlen, &buffer[0], len, nullptr, nullptr );
29 if( len == 0 )
30 {
31 std::ostringstream ss;
32 ss << "WideCharToMultiByte(...) returned 0 and GetLastError() is " << GetLastError();
33 throw std::runtime_error( ss.str() );
34 }
35
36 return buffer;
37}
38
39
40inline std::string win_to_utf( std::wstring const & s )
41{
42 return win_to_utf( s.c_str(), (int) s.length() );
43}
44
45
46} // namespace windows
47} // namespace string
48} // namespace utilities
49#endif
Definition: stabilized-value.h:12