ReactOS  0.4.13-dev-687-g023794c
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 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
HINSTANCE hInstance
Definition: charmap.c:20
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static LPWSTR
Definition: misc.c:35
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23

◆ 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 }
_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
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HINSTANCE hInstance
Definition: charmap.c:20
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
#define RT_STRING
Definition: pedump.c:368
unsigned int UINT
Definition: ndis.h:50
static LPWSTR
Definition: misc.c:35
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LoadAndFormatString()

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

Definition at line 90 of file misc.c.

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 }
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
char ** Args
Definition: acdebug.h:343
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
#define va_start(ap, A)
Definition: acmsvcex.h:91

◆ LocalizedError()

VOID LocalizedError ( IN UINT  uID,
  ... 
)

Definition at line 103 of file misc.c.

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 }
uint16_t * PWSTR
Definition: typedefs.h:54
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
char ** Args
Definition: acdebug.h:343
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define MB_ICONERROR
Definition: winuser.h:781
TCHAR szAppName[128]
Definition: solitaire.cpp:16
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
#define HeapFree(x, y, z)
Definition: compat.h:394
HANDLE hProcessHeap
Definition: kbswitch.c:25

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 */
76  lpFormat,
77  0,
78  0,
79  (LPWSTR)lpTarget,
80  0,
81  Args);
82 
84  }
85 
86  return Ret;
87 }
uint16_t * PWSTR
Definition: typedefs.h:54
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
char ** Args
Definition: acdebug.h:343
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR lpFormat
Definition: trayclock.cpp:32
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
HANDLE hProcessHeap
Definition: kbswitch.c:25

Referenced by LoadAndFormatString(), and LocalizedError().