ReactOS 0.4.15-dev-5672-gf73ac17
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

static INT LengthOfStrResource (IN UINT uID)
 
int AllocAndLoadString (OUT LPWSTR *lpTarget, IN UINT uID)
 
static DWORD VarListLoadAndFormatString (IN UINT uID, OUT PWSTR *lpTarget, IN va_list *Args)
 
DWORD LoadAndFormatString (IN UINT uID, OUT PWSTR *lpTarget,...)
 
VOID LocalizedError (IN UINT uID,...)
 

Function Documentation

◆ AllocAndLoadString()

int AllocAndLoadString ( OUT LPWSTR lpTarget,
IN UINT  uID 
)

Definition at line 42 of file misc.c.

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}
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
int32_t INT
Definition: typedefs.h:58
#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)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LengthOfStrResource()

static INT LengthOfStrResource ( IN UINT  uID)
static

Definition at line 12 of file misc.c.

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}
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
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
_In_ LPCSTR lpName
Definition: winbase.h:2776
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

◆ LoadAndFormatString()

DWORD LoadAndFormatString ( IN UINT  uID,
OUT PWSTR lpTarget,
  ... 
)

Definition at line 90 of file misc.c.

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}
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
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD VarListLoadAndFormatString(IN UINT uID, OUT PWSTR *lpTarget, IN va_list *Args)
Definition: misc.c:66

◆ LocalizedError()

VOID LocalizedError ( IN UINT  uID,
  ... 
)

Definition at line 103 of file misc.c.

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}
#define HeapFree(x, y, z)
Definition: compat.h:735
HANDLE hProcessHeap
Definition: kbswitch.c:34
TCHAR szAppName[128]
Definition: solitaire.cpp:17
uint16_t * PWSTR
Definition: typedefs.h:56
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:781

Referenced by DoFileSave(), and InitFont().

◆ VarListLoadAndFormatString()

static DWORD VarListLoadAndFormatString ( IN UINT  uID,
OUT PWSTR lpTarget,
IN va_list Args 
)
static

Definition at line 66 of file misc.c.

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}
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419

Referenced by LoadAndFormatString(), and LocalizedError().