ReactOS 0.4.15-dev-5666-gc548b97
misc.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static INT LengthOfStrResource (IN HINSTANCE hInst, IN UINT uID)
 
static INT AllocAndLoadString (OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPWSTR *lpTarget,...)
 
LPARAM ListViewGetSelectedItemData (IN HWND hwnd)
 
BOOL ListViewSelectItem (IN HWND hwnd, IN INT Index)
 
HRESULT InitializeObjectPicker (IN PCWSTR ServerName, IN PSI_OBJECT_INFO ObjectInfo, OUT IDsObjectPicker **pDsObjectPicker)
 
HRESULT InvokeObjectPickerDialog (IN IDsObjectPicker *pDsObjectPicker, IN HWND hwndParent OPTIONAL, IN POBJPICK_SELECTED_SID SelectedSidCallback, IN PVOID Context OPTIONAL)
 
VOID FreeObjectPicker (IN IDsObjectPicker *pDsObjectPicker)
 

Variables

static PCWSTR ObjectPickerAttributes []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file misc.c.

Function Documentation

◆ AllocAndLoadString()

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

Definition at line 76 of file misc.c.

79{
80 INT ln;
81
83 uID);
84 if (ln++ > 0)
85 {
86 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
87 ln * sizeof(WCHAR));
88 if ((*lpTarget) != NULL)
89 {
90 INT Ret;
91 if (!(Ret = LoadStringW(hInst, uID, *lpTarget, ln)))
92 {
93 LocalFree((HLOCAL)(*lpTarget));
94 }
95 return Ret;
96 }
97 }
98 return 0;
99}
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define NULL
Definition: types.h:112
HINSTANCE hInst
Definition: dxdiag.c:13
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

◆ FreeObjectPicker()

VOID FreeObjectPicker ( IN IDsObjectPicker *  pDsObjectPicker)

Definition at line 335 of file misc.c.

336{
337 pDsObjectPicker->lpVtbl->Release(pDsObjectPicker);
338}

◆ InitializeObjectPicker()

HRESULT InitializeObjectPicker ( IN PCWSTR  ServerName,
IN PSI_OBJECT_INFO  ObjectInfo,
OUT IDsObjectPicker **  pDsObjectPicker 
)

Definition at line 176 of file misc.c.

179{
180 HRESULT hRet;
181
182 *pDsObjectPicker = NULL;
183
184 hRet = CoCreateInstance(&CLSID_DsObjectPicker,
185 NULL,
186 CLSCTX_INPROC_SERVER,
187 &IID_IDsObjectPicker,
188 (LPVOID*)pDsObjectPicker);
189 if (SUCCEEDED(hRet))
190 {
191 DSOP_INIT_INFO InitInfo;
192 UINT i;
193 static DSOP_SCOPE_INIT_INFO Scopes[] =
194 {
195 {
196 sizeof(DSOP_SCOPE_INIT_INFO),
200 {
201 {
202 0,
203 0,
204 0
205 },
208 },
209 NULL,
210 NULL,
211 S_OK
212 },
213 };
214
215 InitInfo.cbSize = sizeof(InitInfo);
216 InitInfo.pwzTargetComputer = ServerName;
217 InitInfo.cDsScopeInfos = sizeof(Scopes) / sizeof(Scopes[0]);
218 InitInfo.aDsScopeInfos = Scopes;
222
223 for (i = 0; i < InitInfo.cDsScopeInfos; i++)
224 {
225 if ((ObjectInfo->dwFlags & SI_SERVER_IS_DC) &&
227 {
228 /* only set the domain controller string if we know the target
229 computer is a domain controller and the scope type is an
230 up-level domain to which the target computer is joined */
231 InitInfo.aDsScopeInfos[i].pwzDcName = InitInfo.pwzTargetComputer;
232 }
233 }
234
235 hRet = (*pDsObjectPicker)->lpVtbl->Initialize(*pDsObjectPicker,
236 &InitInfo);
237
238 if (FAILED(hRet))
239 {
240 /* delete the object picker in case initialization failed! */
241 (*pDsObjectPicker)->lpVtbl->Release(*pDsObjectPicker);
242 }
243 }
244
245 return hRet;
246}
#define SI_SERVER_IS_DC
Definition: accctrl.h:126
static PCWSTR ObjectPickerAttributes[]
Definition: misc.c:34
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
unsigned int UINT
Definition: ndis.h:50
#define DSOP_SCOPE_FLAG_STARTING_SCOPE
Definition: objsel.h:80
#define DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS
Definition: objsel.h:86
#define DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS
Definition: objsel.h:52
#define DSOP_FLAG_MULTISELECT
Definition: objsel.h:104
#define DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS
Definition: objsel.h:87
#define DSOP_SCOPE_TYPE_TARGET_COMPUTER
Definition: objsel.h:121
#define DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
Definition: objsel.h:68
#define DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
Definition: objsel.h:122
#define DSOP_DOWNLEVEL_FILTER_USERS
Definition: objsel.h:51
struct _DSOP_SCOPE_INIT_INFO DSOP_SCOPE_INIT_INFO
#define DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
Definition: objsel.h:53
ULONG cAttributesToFetch
Definition: objsel.h:114
ULONG cbSize
Definition: objsel.h:109
PCWSTR * apwzAttributeNames
Definition: objsel.h:115
PDSOP_SCOPE_INIT_INFO aDsScopeInfos
Definition: objsel.h:112
ULONG cDsScopeInfos
Definition: objsel.h:111
PCWSTR pwzTargetComputer
Definition: objsel.h:110
ULONG flOptions
Definition: objsel.h:113

Referenced by SecurityPageProc().

◆ InvokeObjectPickerDialog()

HRESULT InvokeObjectPickerDialog ( IN IDsObjectPicker *  pDsObjectPicker,
IN HWND hwndParent  OPTIONAL,
IN POBJPICK_SELECTED_SID  SelectedSidCallback,
IN PVOID Context  OPTIONAL 
)

Definition at line 249 of file misc.c.

253{
254 IDataObject *pdo = NULL;
255 HRESULT hRet;
256
257 hRet = pDsObjectPicker->lpVtbl->InvokeDialog(pDsObjectPicker,
259 &pdo);
260 if (hRet == S_OK)
261 {
262 STGMEDIUM stm;
263 FORMATETC fe;
264
266 fe.ptd = NULL;
267 fe.dwAspect = DVASPECT_CONTENT;
268 fe.lindex = -1;
269 fe.tymed = TYMED_HGLOBAL;
270
271 hRet = pdo->lpVtbl->GetData(pdo,
272 &fe,
273 &stm);
274 if (SUCCEEDED(hRet))
275 {
276 PDS_SELECTION_LIST SelectionList = (PDS_SELECTION_LIST)GlobalLock(stm.hGlobal);
277 if (SelectionList != NULL)
278 {
279 LPVARIANT vSid;
280 PSID pSid;
281 UINT i;
282 BOOL contLoop = TRUE;
283
284 for (i = 0; i < SelectionList->cItems && contLoop; i++)
285 {
286 vSid = SelectionList->aDsSelection[i].pvarFetchedAttributes;
287
288 if (vSid != NULL && V_VT(vSid) == (VT_ARRAY | VT_UI1))
289 {
290 hRet = SafeArrayAccessData(V_ARRAY(vSid),
291 (void **)&pSid);
292 if (FAILED(hRet))
293 {
294 break;
295 }
296
297 if (pSid != NULL)
298 {
299 contLoop = SelectedSidCallback(pDsObjectPicker,
301 pSid,
302 Context);
303 }
304
306 }
307 }
308
309 GlobalUnlock(stm.hGlobal);
310
311 if (SUCCEEDED(hRet))
312 {
313 /* return S_OK instead of possible other success codes if
314 everything went well */
315 hRet = S_OK;
316 }
317 }
318 else
319 {
320 /* unable to translate the selection pointer handle, indicate
321 failure */
322 hRet = E_FAIL;
323 }
324
325 ReleaseStgMedium(&stm);
326 }
327
328 pdo->lpVtbl->Release(pdo);
329 }
330
331 return hRet;
332}
static HWND hwndParent
Definition: cryptui.c:300
#define E_FAIL
Definition: ddrawi.h:102
#define TRUE
Definition: types.h:120
@ VT_ARRAY
Definition: compat.h:2341
@ VT_UI1
Definition: compat.h:2311
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Definition: safearray.c:1137
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
Definition: safearray.c:1168
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
static PSID pSid
Definition: security.c:74
struct _DS_SELECTION_LIST * PDS_SELECTION_LIST
#define CFSTR_DSOP_DS_SELECTION_LIST
Definition: objsel.h:27
#define V_ARRAY(A)
Definition: oleauto.h:222
#define V_VT(A)
Definition: oleauto.h:211
DS_SELECTION aDsSelection[ANYSIZE_ARRAY]
Definition: objsel.h:146
VARIANT * pvarFetchedAttributes
Definition: objsel.h:138
#define RegisterClipboardFormat
Definition: winuser.h:5828

Referenced by SecurityPageProc().

◆ LengthOfStrResource()

static INT LengthOfStrResource ( IN HINSTANCE  hInst,
IN UINT  uID 
)
static

Definition at line 40 of file misc.c.

42{
43 HRSRC hrSrc;
44 HGLOBAL hRes;
45 LPWSTR lpName, lpStr;
46
47 if (hInst == NULL)
48 {
49 return -1;
50 }
51
52 /* There are always blocks of 16 strings */
53 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
54
55 /* Find the string table block */
56 if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
57 (hRes = LoadResource(hInst, hrSrc)) &&
58 (lpStr = LockResource(hRes)))
59 {
60 UINT x;
61
62 /* Find the string we're looking for */
63 uID &= 0xF; /* position in the block, same as % 16 */
64 for (x = 0; x < uID; x++)
65 {
66 lpStr += (*lpStr) + 1;
67 }
68
69 /* Found the string */
70 return (int)(*lpStr);
71 }
72 return -1;
73}
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
#define RT_STRING
Definition: pedump.c:368
_In_ LPCSTR lpName
Definition: winbase.h:2776
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ ListViewGetSelectedItemData()

LPARAM ListViewGetSelectedItemData ( IN HWND  hwnd)

Definition at line 134 of file misc.c.

135{
136 int Index;
137
139 -1,
141 if (Index != -1)
142 {
143 LVITEM li;
144
145 li.mask = LVIF_PARAM;
146 li.iItem = Index;
147 li.iSubItem = 0;
148
150 &li))
151 {
152 return li.lParam;
153 }
154 }
155
156 return 0;
157}
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
#define LVNI_SELECTED
Definition: commctrl.h:2424
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2434
#define LVITEM
Definition: commctrl.h:2375
#define LVIF_PARAM
Definition: commctrl.h:2311
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2394
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by DisplaySelectedDeviceProperties(), SecurityPageProc(), UpdateControlStates(), UpdateDevicesListViewControl(), and UpdatePrincipalInfo().

◆ ListViewSelectItem()

BOOL ListViewSelectItem ( IN HWND  hwnd,
IN INT  Index 
)

Definition at line 160 of file misc.c.

162{
163 LVITEM li;
164
165 li.mask = LVIF_STATE;
166 li.iItem = Index;
167 li.iSubItem = 0;
168 li.state = LVIS_SELECTED;
169 li.stateMask = LVIS_SELECTED;
170
171 return ListView_SetItem(hwnd,
172 &li);
173}
#define LVIF_STATE
Definition: commctrl.h:2312
#define LVIS_SELECTED
Definition: commctrl.h:2319
#define ListView_SetItem(hwnd, pitem)
Definition: commctrl.h:2401

Referenced by SecurityPageProc().

◆ LoadAndFormatString()

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

Definition at line 102 of file misc.c.

106{
107 DWORD Ret = 0;
109 va_list lArgs;
110
112 hInstance,
113 uID) > 0)
114 {
115 va_start(lArgs, lpTarget);
116 /* let's use FormatMessage to format it because it has the ability to allocate
117 memory automatically */
119 lpFormat,
120 0,
121 0,
122 (LPWSTR)lpTarget,
123 0,
124 &lArgs);
125 va_end(lArgs);
126
128 }
129
130 return Ret;
131}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
HINSTANCE hInstance
Definition: charmap.c:19
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419

Variable Documentation

◆ ObjectPickerAttributes

PCWSTR ObjectPickerAttributes[]
static
Initial value:
=
{
L"ObjectSid",
}
#define L(x)
Definition: ntvdm.h:50

Definition at line 34 of file misc.c.

Referenced by InitializeObjectPicker().