1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 // ---------------------------------------------------------------------------
7 // ---------------------------------------------------------------------------
14 #define DEFAULT_RESOURCE_STRING_SIZE 255
16 //----------------------------------------------------------------------------
17 // Load the string resource into this string.
18 //----------------------------------------------------------------------------
19 BOOL SString::LoadResource(CCompRC::ResourceCategory eCategory, int resourceID)
21 return SUCCEEDED(LoadResourceAndReturnHR(eCategory, resourceID));
24 HRESULT SString::LoadResourceAndReturnHR(CCompRC::ResourceCategory eCategory, int resourceID)
27 return LoadResourceAndReturnHR(NULL, eCategory,resourceID);
30 HRESULT SString::LoadResourceAndReturnHR(CCompRC* pResourceDLL, CCompRC::ResourceCategory eCategory, int resourceID)
41 #ifndef FEATURE_UTILCODE_NO_DEPENDENCIES
42 if (pResourceDLL == NULL)
44 pResourceDLL = CCompRC::GetDefaultResourceDll();
47 if (pResourceDLL != NULL)
54 if (GetRawCount() == 0)
55 Resize(DEFAULT_RESOURCE_STRING_SIZE, REPRESENTATION_UNICODE);
59 // First try and load the string in the amount of space that we have.
60 // In fatal error reporting scenarios, we may not have enough memory to
61 // allocate a larger buffer.
63 hr = pResourceDLL->LoadString(eCategory, resourceID, GetRawUnicode(), GetRawCount()+1, &size);
64 if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
72 // Although we cannot generally detect truncation, we can tell if we
73 // used up all the space (in which case we will assume truncation.)
74 if (size < (int)GetRawCount())
80 // Double the size and try again.
81 Resize(size*2, REPRESENTATION_UNICODE);
87 Truncate(Begin() + (COUNT_T) wcslen(GetRawUnicode()));
97 EX_END_CATCH(SwallowAllExceptions);
99 #endif //!FEATURE_UTILCODE_NO_DEPENDENCIES
102 } // SString::LoadResourceAndReturnHR