2 * PROJECT: ReactOS VGA Font Editor
3 * LICENSE: GNU General Public License Version 2.0 only
4 * FILE: devutils/vgafontedit/misc.c
5 * PURPOSE: Some miscellaneous resource functions (copied from "devmgmt") and modified
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
7 * Copyright 2008 Colin Finck <mail@colinfinck.de>
13 LengthOfStrResource(IN UINT uID
)
19 /* There are always blocks of 16 strings */
20 lpName
= (PWSTR
) MAKEINTRESOURCEW((uID
>> 4) + 1);
22 /* Find the string table block */
23 if ((hrSrc
= FindResourceW(hInstance
, lpName
, (PWSTR
)RT_STRING
)) != 0 &&
24 (hRes
= LoadResource(hInstance
, hrSrc
)) != 0 &&
25 (lpStr
= (PWSTR
)LockResource(hRes
)) != 0)
29 /* Find the string we're looking for */
30 uID
&= 0xF; /* position in the block, same as % 16 */
32 for (x
= 0; x
< uID
; x
++)
33 lpStr
+= (*lpStr
) + 1;
35 /* Found the string */
43 AllocAndLoadString(OUT PWSTR
*lpTarget
, IN UINT uID
)
47 ln
= LengthOfStrResource(uID
);
51 (*lpTarget
) = (PWSTR
) HeapAlloc( hProcessHeap
, 0, ln
* sizeof(WCHAR
) );
57 nRet
= LoadStringW(hInstance
, uID
, *lpTarget
, ln
);
60 HeapFree(hProcessHeap
, 0, *lpTarget
);
70 VarListLoadAndFormatString(IN UINT uID
, OUT PWSTR
*lpTarget
, IN
va_list* Args
)
75 if (AllocAndLoadString(&lpFormat
, uID
) > 0)
77 /* let's use FormatMessage to format it because it has the ability to allocate
78 memory automatically */
79 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
87 HeapFree(hProcessHeap
, 0, lpFormat
);
94 LoadAndFormatString(IN UINT uID
, OUT PWSTR
*lpTarget
, ...)
99 va_start(Args
, lpTarget
);
100 Ret
= VarListLoadAndFormatString(uID
, lpTarget
, &Args
);
107 LocalizedError(IN UINT uID
, ...)
113 VarListLoadAndFormatString(uID
, &pszError
, &Args
);
116 MessageBoxW(NULL
, pszError
, szAppName
, MB_ICONERROR
);
117 HeapFree(hProcessHeap
, 0, pszError
);