[LSASRV]
[reactos.git] / reactos / dll / win32 / lsasrv / utils.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Security Account Manager (SAM) Server
4 * FILE: reactos/dll/win32/lsasrv/utils.c
5 * PURPOSE: Utility functions
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 /* INCLUDES ****************************************************************/
11
12 #include "lsasrv.h"
13
14 WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
15
16
17 /* GLOBALS *****************************************************************/
18
19
20 /* FUNCTIONS ***************************************************************/
21
22 INT
23 LsapLoadString(HINSTANCE hInstance,
24 UINT uId,
25 LPWSTR lpBuffer,
26 INT nBufferMax)
27 {
28 HGLOBAL hmem;
29 HRSRC hrsrc;
30 WCHAR *p;
31 int string_num;
32 int i;
33
34 /* Use loword (incremented by 1) as resourceid */
35 hrsrc = FindResourceW(hInstance,
36 MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
37 (LPWSTR)RT_STRING);
38 if (!hrsrc)
39 return 0;
40
41 hmem = LoadResource(hInstance, hrsrc);
42 if (!hmem)
43 return 0;
44
45 p = LockResource(hmem);
46 string_num = uId & 0x000f;
47 for (i = 0; i < string_num; i++)
48 p += *p + 1;
49
50 i = min(nBufferMax - 1, *p);
51 if (i > 0)
52 {
53 memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
54 lpBuffer[i] = 0;
55 }
56 else
57 {
58 if (nBufferMax > 1)
59 {
60 lpBuffer[0] = 0;
61 return 0;
62 }
63 }
64
65 return i;
66 }
67
68 /* EOF */