MCPcopy Create free account
hub / github.com/OpenVPN/openvpn-gui / LoadStringLang

Function LoadStringLang

localization.c:200–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200static int
201LoadStringLang(UINT stringId, LANGID langId, PTSTR buffer, int bufferSize, va_list args)
202{
203 PWCH entry;
204 PTSTR resBlockId = MAKEINTRESOURCE(stringId / 16 + 1);
205 int resIndex = stringId & 15;
206
207 /* find resource block for string */
208 HRSRC res = FindResourceLang(RT_STRING, resBlockId, langId);
209 if (res == NULL)
210 {
211 goto err;
212 }
213
214 /* get pointer to first entry in resource block */
215 entry = (PWCH)LoadResource(o.hInstance, res);
216 if (entry == NULL)
217 {
218 goto err;
219 }
220
221 /* search for string in block */
222 for (int i = 0; i < 16; i++)
223 {
224 /* skip over this entry */
225 if (i != resIndex)
226 {
227 entry += ((*entry) + 1);
228 continue;
229 }
230
231 /* string does not exist */
232 if (i == resIndex && *entry == 0)
233 {
234 break;
235 }
236
237 /* string found, copy it */
238 PTSTR formatStr = (PTSTR)malloc((*entry + 1) * sizeof(TCHAR));
239 if (formatStr == NULL)
240 {
241 break;
242 }
243 formatStr[*entry] = 0;
244
245 wcsncpy(formatStr, entry + 1, *entry);
246 _vsntprintf(buffer, bufferSize, formatStr, args);
247 buffer[bufferSize - 1] = 0;
248 free(formatStr);
249 return _tcslen(buffer);
250 }
251
252err:
253 /* not found, try again with the default language */
254 if (langId != fallbackLangId)
255 {
256 return LoadStringLang(stringId, fallbackLangId, buffer, bufferSize, args);
257 }

Callers 3

__LoadLocalizedStringFunction · 0.85
LoadLocalizedStringBufFunction · 0.85
LangListEntryFunction · 0.85

Calls 1

FindResourceLangFunction · 0.85

Tested by

no test coverage detected