ReactOS  0.4.13-dev-66-gc714b7f
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 
11 static 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 
41 int
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 
65 static 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 */
76  lpFormat,
77  0,
78  0,
79  (LPWSTR)lpTarget,
80  0,
81  Args);
82 
84  }
85 
86  return Ret;
87 }
88 
89 DWORD
90 LoadAndFormatString(IN UINT uID, OUT PWSTR *lpTarget, ...)
91 {
92  DWORD Ret;
93  va_list Args;
94 
95  va_start(Args, lpTarget);
96  Ret = VarListLoadAndFormatString(uID, lpTarget, &Args);
97  va_end(Args);
98 
99  return Ret;
100 }
101 
102 VOID
104 {
105  PWSTR pszError;
106  va_list Args;
107 
108  va_start(Args, uID);
109  VarListLoadAndFormatString(uID, &pszError, &Args);
110  va_end(Args);
111 
112  MessageBoxW(NULL, pszError, szAppName, MB_ICONERROR);
113  HeapFree(hProcessHeap, 0, pszError);
114 }
#define IN
Definition: typedefs.h:38
uint16_t * PWSTR
Definition: typedefs.h:54
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
_In_ LPCSTR lpName
Definition: winbase.h:2729
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
char ** Args
Definition: acdebug.h:343
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:86
#define LMEM_FIXED
Definition: winbase.h:349
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID LocalizedError(IN UINT uID,...)
Definition: misc.c:103
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MB_ICONERROR
Definition: winuser.h:781
#define RT_STRING
Definition: pedump.c:368
LPCWSTR lpFormat
Definition: trayclock.cpp:32
TCHAR szAppName[128]
Definition: solitaire.cpp:16
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
static DWORD VarListLoadAndFormatString(IN UINT uID, OUT PWSTR *lpTarget, IN va_list *Args)
Definition: misc.c:66
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int UINT
Definition: ndis.h:50
#define OUT
Definition: typedefs.h:39
static LPWSTR
Definition: misc.c:35
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define HeapFree(x, y, z)
Definition: compat.h:394
HANDLE hProcessHeap
Definition: kbswitch.c:25