1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/win/hstring_reference.h" 6 7 #include <windows.h> 8 9 #include <wchar.h> 10 #include <winstring.h> 11 12 #include "base/check_op.h" 13 #include "base/numerics/safe_conversions.h" 14 15 namespace base::win { 16 HStringReference(const wchar_t * str)17HStringReference::HStringReference(const wchar_t* str) { 18 // String must be null terminated for WindowsCreateStringReference. 19 // nullptr str is OK so long as the length is 0. 20 size_t length = str ? wcslen(str) : 0; 21 const HRESULT hr = ::WindowsCreateStringReference( 22 str, checked_cast<UINT32>(length), &hstring_header_, &hstring_); 23 DCHECK_EQ(hr, S_OK); 24 } 25 26 } // namespace base::win 27