2 * ReactOS Management Console
3 * Copyright (C) 2006 - 2007 Thomas Weidenmueller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 LengthOfStrResource(IN HINSTANCE hInst
,
35 /* There are always blocks of 16 strings */
36 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
38 /* Find the string table block */
39 if ((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
40 (hRes
= LoadResource(hInst
, hrSrc
)) &&
41 (lpStr
= LockResource(hRes
)))
45 /* Find the string we're looking for */
46 uID
&= 0xF; /* position in the block, same as % 16 */
47 for (x
= 0; x
< uID
; x
++)
49 lpStr
+= (*lpStr
) + 1;
52 /* Found the string */
60 AllocAndLoadString(OUT LPTSTR
*lpTarget
,
66 ln
= LengthOfStrResource(hInst
,
70 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
72 if ((*lpTarget
) != NULL
)
75 if (!(Ret
= LoadString(hInst
, uID
, *lpTarget
, ln
)))
77 LocalFree((HLOCAL
)(*lpTarget
));
86 LoadAndFormatString(IN HINSTANCE hInstance
,
95 if (AllocAndLoadString(&lpFormat
,
99 va_start(lArgs
, lpTarget
);
100 /* let's use FormatMessage to format it because it has the ability to allocate
101 memory automatically */
102 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
111 LocalFree((HLOCAL
)lpFormat
);