ReactOS 0.4.15-dev-7677-g8209aa5
misc.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS VGA Font Editor
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Some miscellaneous resource functions
5 * COPYRIGHT: Copyright 2006-2007 Thomas Weidenmueller (thomas@reactsoft.com)
6 * Copyright 2008 Colin Finck (colin@reactos.org)
7 */
8
9#include "precomp.h"
10
11static INT
13{
14 HRSRC hrSrc;
15 HGLOBAL hRes;
16 LPWSTR lpName, lpStr;
17
18 /* There are always blocks of 16 strings */
19 lpName = (LPWSTR)MAKEINTRESOURCEW((uID >> 4) + 1);
20
21 /* Find the string table block */
22 if ((hrSrc = FindResourceW(hInstance, lpName, (LPWSTR)RT_STRING)) &&
23 (hRes = LoadResource(hInstance, hrSrc)) &&
24 (lpStr = LockResource(hRes)))
25 {
26 UINT x;
27
28 /* Find the string we're looking for */
29 uID &= 0xF; /* position in the block, same as % 16 */
30 for (x = 0; x < uID; x++)
31 {
32 lpStr += (*lpStr) + 1;
33 }
34
35 /* Found the string */
36 return (int)(*lpStr);
37 }
38 return -1;
39}
40
41int
43 IN UINT uID)
44{
45 INT ln;
46
47 ln = LengthOfStrResource(uID);
48 if (ln++ > 0)
49 {
50 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
51 ln * sizeof(WCHAR));
52 if ((*lpTarget) != NULL)
53 {
54 INT Ret;
55 if (!(Ret = LoadStringW(hInstance, uID, *lpTarget, ln)))
56 {
57 LocalFree((HLOCAL)(*lpTarget));
58 }
59 return Ret;
60 }
61 }
62 return 0;
63}
64
65static DWORD
67{
68 DWORD Ret = 0;
70
71 if (AllocAndLoadString(&lpFormat, uID) > 0)
72 {
73 /* let's use FormatMessage to format it because it has the ability to allocate
74 memory automatically */
77 0,
78 0,
79 (LPWSTR)lpTarget,
80 0,
81 Args);
82
84 }
85
86 return Ret;
87}
88
90LoadAndFormatString(IN UINT uID, OUT PWSTR *lpTarget, ...)
91{
92 DWORD Ret;
94
95 va_start(Args, lpTarget);
96 Ret = VarListLoadAndFormatString(uID, lpTarget, &Args);
97 va_end(Args);
98
99 return Ret;
100}
101
102VOID
104{
105 PWSTR pszError;
107
108 va_start(Args, uID);
109 VarListLoadAndFormatString(uID, &pszError, &Args);
110 va_end(Args);
111
113 HeapFree(hProcessHeap, 0, pszError);
114}
char ** Args
Definition: acdebug.h:353
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:85
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define HeapFree(x, y, z)
Definition: compat.h:735
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
HANDLE hProcessHeap
Definition: kbswitch.c:43
static DWORD VarListLoadAndFormatString(IN UINT uID, OUT PWSTR *lpTarget, IN va_list *Args)
Definition: misc.c:66
VOID LocalizedError(IN UINT uID,...)
Definition: misc.c:103
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
TCHAR szAppName[128]
Definition: solitaire.cpp:18
LPCWSTR lpFormat
Definition: trayclock.cpp:32
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define LMEM_FIXED
Definition: winbase.h:368
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:786
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184