ReactOS  0.4.12-dev-43-g63b00d8
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

INT LengthOfStrResource (IN HINSTANCE hInst, IN UINT uID)
 
static INT AllocAndLoadString (OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
 

Function Documentation

◆ AllocAndLoadString()

static INT AllocAndLoadString ( OUT LPTSTR lpTarget,
IN HINSTANCE  hInst,
IN UINT  uID 
)
static

Definition at line 60 of file misc.c.

Referenced by _tWinMain(), AboutDialogProc(), AddToolbarButton(), ChangeListViewText(), CreateApplicationWindow(), DoCreate(), DoDeleteService(), DoOpenFile(), DoSaveFile(), FontWndProc(), InitDialog(), InitRecoveryPage(), LoadAndFormatString(), MainWndCreateFloatWindows(), NewDocSelDlgProc(), OnCreate(), ResetProgressDialog(), SetServiceStatusText(), SetStartupType(), TdbInsertToolbar(), TV1_AddDependantsToTree(), TV2_AddDependantsToTree(), UpdateServiceCount(), and wWinMain().

63 {
64  INT ln;
65 
67  uID);
68  if (ln++ > 0)
69  {
70  (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
71  ln * sizeof(TCHAR));
72  if ((*lpTarget) != NULL)
73  {
74  INT Ret;
75  if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
76  {
77  LocalFree((HLOCAL)(*lpTarget));
78  }
79  return Ret;
80  }
81  }
82  return 0;
83 }
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
char TCHAR
Definition: xmlstorage.h:189
HINSTANCE hInst
Definition: dxdiag.c:13
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
#define LoadString
Definition: winuser.h:5685

◆ LengthOfStrResource()

INT LengthOfStrResource ( IN HINSTANCE  hInst,
IN UINT  uID 
)

Definition at line 23 of file misc.c.

Referenced by AllocAndLoadString(), and DeviceProblemTextW().

25 {
26  HRSRC hrSrc;
27  HGLOBAL hRes;
28  LPWSTR lpName, lpStr;
29 
30  if (hInst == NULL)
31  {
32  return -1;
33  }
34 
35  /* There are always blocks of 16 strings */
36  lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
37 
38  /* Find the string table block */
39  if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
40  (hRes = LoadResource(hInst, hrSrc)) &&
41  (lpStr = LockResource(hRes)))
42  {
43  UINT x;
44 
45  /* Find the string we're looking for */
46  uID &= 0xF; /* position in the block, same as % 16 */
47  for (x = 0; x < uID; x++)
48  {
49  lpStr += (*lpStr) + 1;
50  }
51 
52  /* Found the string */
53  return (int)(*lpStr);
54  }
55  return -1;
56 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
_In_ LPCSTR lpName
Definition: winbase.h:2729
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
HINSTANCE hInst
Definition: dxdiag.c:13
INT x
Definition: msvc.h:62
static LPWSTR
Definition: misc.c:35
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LoadAndFormatString()

DWORD LoadAndFormatString ( IN HINSTANCE  hInstance,
IN UINT  uID,
OUT LPTSTR lpTarget,
  ... 
)

Definition at line 86 of file misc.c.

Referenced by CreateFontWindow(), CreateNewConsoleTitle(), EditSecurity(), FontWndProc(), GetDisplayStringFromSidRequestResult(), GetPrincipalAccountNameString(), MainWndCommand(), and UpdateControlStates().

90 {
91  DWORD Ret = 0;
93  va_list lArgs;
94 
95  if (AllocAndLoadString(&lpFormat,
96  hInstance,
97  uID) != 0)
98  {
99  va_start(lArgs, lpTarget);
100  /* let's use FormatMessage to format it because it has the ability to allocate
101  memory automatically */
103  lpFormat,
104  0,
105  0,
106  (LPTSTR)lpTarget,
107  0,
108  &lArgs);
109  va_end(lArgs);
110 
111  LocalFree((HLOCAL)lpFormat);
112  }
113 
114  return Ret;
115 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
static INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:60
CHAR * LPTSTR
Definition: xmlstorage.h:192
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
char * va_list
Definition: acmsvcex.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3609
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define va_start(ap, A)
Definition: acmsvcex.h:91
WCHAR * LPWSTR
Definition: xmlstorage.h:184