ReactOS 0.4.15-dev-7842-g558ab78
misc.c File Reference
#include <user32.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

VOID WINAPI UserSetLastError (IN DWORD dwErrCode)
 
VOID WINAPI UserSetLastNTError (IN NTSTATUS Status)
 
PTHREADINFO GetW32ThreadInfo (VOID)
 
BOOL WINAPI GetUserObjectSecurity (IN HANDLE hObject, IN PSECURITY_INFORMATION pSecurityInfo, OUT PSECURITY_DESCRIPTOR pSecurityDescriptor, IN DWORD dwLength, OUT PDWORD pdwLengthNeeded)
 
BOOL WINAPI SetUserObjectSecurity (IN HANDLE hObject, IN PSECURITY_INFORMATION pSecurityInfo, IN PSECURITY_DESCRIPTOR pSecurityDescriptor)
 
BOOL WINAPI IsGUIThread (BOOL bConvert)
 
BOOL FASTCALL TestWindowProcess (PWND Wnd)
 
BOOL FASTCALL TestState (PWND pWnd, UINT Flag)
 
PUSER_HANDLE_ENTRY FASTCALL GetUser32Handle (HANDLE handle)
 
PVOID FASTCALL ValidateHandle (HANDLE handle, UINT uType)
 
PVOID FASTCALL ValidateHandleNoErr (HANDLE handle, UINT uType)
 
PCALLPROCDATA FASTCALL ValidateCallProc (HANDLE hCallProc)
 
PWND FASTCALL ValidateHwnd (HWND hwnd)
 
PWND FASTCALL ValidateHwndNoErr (HWND hwnd)
 
PWND FASTCALL GetThreadDesktopWnd (VOID)
 
PWND FASTCALL ValidateHwndOrDesk (HWND hwnd)
 
DWORD WINAPI WCSToMBEx (WORD CodePage, LPWSTR UnicodeString, LONG UnicodeSize, LPSTR *MBString, LONG MBSize, BOOL Allocate)
 
DWORD WINAPI MBToWCSEx (WORD CodePage, LPSTR MBString, LONG MBSize, LPWSTR *UnicodeString, LONG UnicodeSize, BOOL Allocate)
 

Variables

static const BOOL g_ObjectHeapTypeShared [TYPE_CTYPES]
 

Function Documentation

◆ GetThreadDesktopWnd()

PWND FASTCALL GetThreadDesktopWnd ( VOID  )

Definition at line 397 of file misc.c.

398{
400 if (Wnd != NULL)
401 Wnd = DesktopPtrToUser(Wnd);
402 return Wnd;
403}
#define NULL
Definition: types.h:112
static PVOID FASTCALL DesktopPtrToUser(PVOID ptr)
Definition: utils.c:324
struct _WND * spwnd
Definition: ntuser.h:137
Definition: ntuser.h:694
static __inline PDESKTOPINFO GetThreadDesktopInfo(VOID)
Definition: user_x.h:43

Referenced by GetDesktopWindow(), IsChild(), and ValidateHwndOrDesk().

◆ GetUser32Handle()

PUSER_HANDLE_ENTRY FASTCALL GetUser32Handle ( HANDLE  handle)

Definition at line 195 of file misc.c.

196{
197 INT Index;
199
200 if (!handle) return NULL;
201
202 Index = (((UINT_PTR)handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
203
204 if (Index < 0 || Index >= gHandleTable->nb_handles)
205 return NULL;
206
208 return NULL;
209
210 generation = (UINT_PTR)handle >> 16;
211
213 return &gHandleEntries[Index];
214
215 return NULL;
216}
_In_ uint64_t _In_ uint64_t _In_ uint64_t generation
Definition: btrfs.c:2996
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define FIRST_USER_HANDLE
Definition: ntuser.h:10
static PVOID ptr
Definition: dispmode.c:27
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned short USHORT
Definition: pedump.c:61
int32_t INT
Definition: typedefs.h:58
PUSER_HANDLE_ENTRY gHandleEntries
Definition: dllmain.c:33
_In_ WDFCOLLECTION _In_ ULONG Index
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by ValidateCallProc(), ValidateHandle(), and ValidateHandleNoErr().

◆ GetUserObjectSecurity()

BOOL WINAPI GetUserObjectSecurity ( IN HANDLE  hObject,
IN PSECURITY_INFORMATION  pSecurityInfo,
OUT PSECURITY_DESCRIPTOR  pSecurityDescriptor,
IN DWORD  dwLength,
OUT PDWORD  pdwLengthNeeded 
)

Definition at line 75 of file misc.c.

82{
84
86 *pSecurityInfo,
87 pSecurityDescriptor,
89 pdwLengthNeeded);
90 if (!NT_SUCCESS(Status))
91 {
93 return FALSE;
94 }
95
96 return TRUE;
97}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static DWORD DWORD * dwLength
Definition: fusion.c:86
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI NtQuerySecurityObject(IN HANDLE Handle, IN SECURITY_INFORMATION SecurityInformation, OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN ULONG Length, OUT PULONG ResultLength)
Definition: obsecure.c:803
VOID WINAPI UserSetLastNTError(IN NTSTATUS Status)
Definition: misc.c:25

◆ GetW32ThreadInfo()

◆ IsGUIThread()

BOOL WINAPI IsGUIThread ( BOOL  bConvert)

Definition at line 145 of file misc.c.

147{
148 PTHREADINFO ti = (PTHREADINFO)NtCurrentTeb()->Win32ThreadInfo;
149 if (ti == NULL)
150 {
151 if(bConvert)
152 {
154 if ((PTHREADINFO)NtCurrentTeb()->Win32ThreadInfo) return TRUE;
155 else
157 }
158 return FALSE;
159 }
160 else
161 return TRUE;
162}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define SetLastError(x)
Definition: compat.h:752

Referenced by do_InitialDesktop_child().

◆ MBToWCSEx()

DWORD WINAPI MBToWCSEx ( WORD  CodePage,
LPSTR  MBString,
LONG  MBSize,
LPWSTR UnicodeString,
LONG  UnicodeSize,
BOOL  Allocate 
)

Definition at line 457 of file misc.c.

458{
459 DWORD Size;
460 if (MBSize == -1)
461 {
462 MBSize = strlen(MBString)+1;
463 }
464 if (UnicodeSize == -1)
465 {
466 if (!Allocate)
467 {
468 return 0;
469 }
470 UnicodeSize = MBSize;
471 }
472 if (Allocate)
473 {
474 LPWSTR SafeString = RtlAllocateHeap(GetProcessHeap(), 0, UnicodeSize);
475 if (SafeString == NULL)
476 return 0;
477 *UnicodeString = SafeString;
478 }
479 UnicodeSize *= sizeof(WCHAR);
480 if (CodePage == 0)
481 {
482 RtlMultiByteToUnicodeN(*UnicodeString,UnicodeSize,&Size,MBString,MBSize);
483 }
484 else
485 {
486 Size = MultiByteToWideChar(CodePage,0,MBString,MBSize,*UnicodeString,UnicodeSize);
487 }
488 return Size;
489}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define GetProcessHeap()
Definition: compat.h:736
#define MultiByteToWideChar
Definition: compat.h:110
unsigned long DWORD
Definition: ntddk_ex.h:95
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:62
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:814
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ SetUserObjectSecurity()

BOOL WINAPI SetUserObjectSecurity ( IN HANDLE  hObject,
IN PSECURITY_INFORMATION  pSecurityInfo,
IN PSECURITY_DESCRIPTOR  pSecurityDescriptor 
)

Definition at line 120 of file misc.c.

125{
127
128 Status = NtSetSecurityObject(hObject,
129 *pSecurityInfo,
130 pSecurityDescriptor);
131 if (!NT_SUCCESS(Status))
132 {
134 return FALSE;
135 }
136
137 return TRUE;
138}
NTSTATUS WINAPI NtSetSecurityObject(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)

◆ TestState()

BOOL FASTCALL TestState ( PWND  pWnd,
UINT  Flag 
)

Definition at line 177 of file misc.c.

178{
179 UINT bit;
180 bit = 1 << LOWORD(Flag);
181 switch(HIWORD(Flag))
182 {
183 case 0:
184 return (pWnd->state & bit);
185 case 1:
186 return (pWnd->state2 & bit);
187 case 2:
188 return (pWnd->ExStyle2 & bit);
189 }
190 return FALSE;
191}
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
Definition: xml2sdb.h:80
DWORD ExStyle2
Definition: ntuser.h:745
DWORD state2
Definition: ntuser.h:702
DWORD state
Definition: ntuser.h:701
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by NtUserxClearWindowState(), and NtUserxSetWindowState().

◆ TestWindowProcess()

BOOL FASTCALL TestWindowProcess ( PWND  Wnd)

Definition at line 166 of file misc.c.

167{
168 if (Wnd->head.pti == (PTHREADINFO)NtCurrentTeb()->Win32ThreadInfo)
169 return TRUE;
170 else
173}
DWORD_PTR NTAPI NtUserQueryWindow(HWND hWnd, DWORD Index)
Definition: window.c:4189
#define QUERY_WINDOW_UNIQUE_PROCESS_ID
Definition: ntuser.h:2827
HANDLE UniqueProcess
Definition: compat.h:825
THRDESKHEAD head
Definition: ntuser.h:695
uint32_t DWORD_PTR
Definition: typedefs.h:65
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

Referenced by DIALOG_FindMsgDestination(), GetWindowTextA(), GetWindowTextLengthA(), GetWindowTextLengthW(), GetWindowTextW(), IntGetWindowLong(), IsDialogMessageW(), SetWindowTextA(), and SetWindowTextW().

◆ UserSetLastError()

VOID WINAPI UserSetLastError ( IN DWORD  dwErrCode)

Definition at line 13 of file misc.c.

14{
15 /*
16 * Equivalent of SetLastError in kernel32, but without breaking
17 * into the debugger nor checking whether the last old error is
18 * the same as the one we are going to set.
19 */
20 NtCurrentTeb()->LastErrorValue = dwErrCode;
21}

Referenced by EndTask(), ExitWindowsWorker(), and UserSetLastNTError().

◆ UserSetLastNTError()

VOID WINAPI UserSetLastNTError ( IN NTSTATUS  Status)

Definition at line 25 of file misc.c.

26{
27 /*
28 * Equivalent of BaseSetLastNTError in kernel32, but using
29 * UserSetLastError: convert from NT to Win32, then set.
30 */
32}
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
VOID WINAPI UserSetLastError(IN DWORD dwErrCode)
Definition: misc.c:13

Referenced by EndTask(), ExitWindowsWorker(), GetThreadDesktop(), GetUserObjectSecurity(), RegisterLogonProcess(), RegisterServicesProcess(), and SetUserObjectSecurity().

◆ ValidateCallProc()

PCALLPROCDATA FASTCALL ValidateCallProc ( HANDLE  hCallProc)

Definition at line 339 of file misc.c.

340{
342
343 PCALLPROCDATA CallProc = ValidateHandle(hCallProc, TYPE_CALLPROC);
344
345 pEntry = GetUser32Handle(hCallProc);
346
347 if (CallProc != NULL && pEntry->ppi == g_ppi)
348 return CallProc;
349
350 return NULL;
351}
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
@ TYPE_CALLPROC
Definition: ntuser.h:47
Definition: ntuser.h:17
PPROCESSINFO g_ppi
Definition: dllmain.c:29
PVOID FASTCALL ValidateHandle(HANDLE handle, UINT uType)
Definition: misc.c:252
PUSER_HANDLE_ENTRY FASTCALL GetUser32Handle(HANDLE handle)
Definition: misc.c:195

Referenced by CallWindowProcA(), and CallWindowProcW().

◆ ValidateHandle()

PVOID FASTCALL ValidateHandle ( HANDLE  handle,
UINT  uType 
)

Definition at line 252 of file misc.c.

253{
254 PVOID ret;
256
257 ASSERT(uType < TYPE_CTYPES);
258
260
261 if (pEntry && uType == 0)
262 uType = pEntry->type;
263
264// Must have an entry and must be the same type!
265 if ( (!pEntry) ||
266 (pEntry->type != uType) ||
267 !pEntry->ptr ||
268 (pEntry->flags & HANDLEENTRY_DESTROY) || (pEntry->flags & HANDLEENTRY_INDESTROY) )
269 {
270 switch ( uType )
271 { // Test (with wine too) confirms these results!
272 case TYPE_WINDOW:
274 break;
275 case TYPE_MENU:
277 break;
278 case TYPE_CURSOR:
280 break;
283 break;
284 case TYPE_HOOK:
286 break;
287 case TYPE_ACCELTABLE:
289 break;
290 default:
292 break;
293 }
294 return NULL;
295 }
296
297 if (g_ObjectHeapTypeShared[uType])
298 ret = SharedPtrToUser(pEntry->ptr);
299 else
301
302 return ret;
303}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:14
@ TYPE_HOOK
Definition: ntuser.h:45
@ TYPE_CTYPES
Definition: ntuser.h:62
@ TYPE_CURSOR
Definition: ntuser.h:43
@ TYPE_WINDOW
Definition: ntuser.h:41
@ TYPE_ACCELTABLE
Definition: ntuser.h:48
@ TYPE_MENU
Definition: ntuser.h:42
@ TYPE_SETWINDOWPOS
Definition: ntuser.h:44
#define HANDLEENTRY_DESTROY
Definition: ntuser.h:13
#define ASSERT(a)
Definition: mode.c:44
static __inline PVOID SharedPtrToUser(PVOID Ptr)
Definition: user_x.h:4
int ret
static const BOOL g_ObjectHeapTypeShared[TYPE_CTYPES]
Definition: misc.c:221
#define ERROR_INVALID_ACCEL_HANDLE
Definition: winerror.h:884
#define ERROR_INVALID_DWP_HANDLE
Definition: winerror.h:886
#define ERROR_INVALID_MENU_HANDLE
Definition: winerror.h:882
#define ERROR_INVALID_WINDOW_HANDLE
Definition: winerror.h:881
#define ERROR_INVALID_CURSOR_HANDLE
Definition: winerror.h:883
#define ERROR_INVALID_HOOK_HANDLE
Definition: winerror.h:885

Referenced by CheckMenuItem(), GetMenuContextHelpId(), GetMenuDefaultItem(), GetMenuInfo(), GetMenuItemCount(), GetThemeBool(), GetThemeColor(), GetThemeEnumValue(), GetThemeFilename(), GetThemeFont(), GetThemeInt(), GetThemeIntList(), GetThemeMargins(), GetThemeMetric(), GetThemePosition(), GetThemePropertyOrigin(), GetThemeRect(), GetThemeString(), GetThemeSysBool(), GetThemeSysColor(), GetThemeSysFont(), GetThemeSysInt(), GetThemeSysSize(), GetThemeSysString(), Imm32DestroyInputContext(), ImmLockClientImc(), IsMenu(), User32CanSetImeWindowToImc(), User32SetImeWindowOfImc(), UXTHEME_LoadImage(), UXTHEME_SelectImage(), ValidateCallProc(), and ValidateHwnd().

◆ ValidateHandleNoErr()

PVOID FASTCALL ValidateHandleNoErr ( HANDLE  handle,
UINT  uType 
)

Definition at line 310 of file misc.c.

311{
312 PVOID ret;
314
315 ASSERT(uType < TYPE_CTYPES);
316
318
319 if (pEntry && uType == 0)
320 uType = pEntry->type;
321
322// Must have an entry and must be the same type!
323 if ( (!pEntry) || (pEntry->type != uType) || !pEntry->ptr )
324 return NULL;
325
326 if (g_ObjectHeapTypeShared[uType])
327 ret = SharedPtrToUser(pEntry->ptr);
328 else
330
331 return ret;
332}

Referenced by ImmCallImeConsoleIME(), MENU_GetMenu(), and ValidateHwndNoErr().

◆ ValidateHwnd()

PWND FASTCALL ValidateHwnd ( HWND  hwnd)

Definition at line 359 of file misc.c.

360{
363
364 /* See if the window is cached */
365 if (hwnd && hwnd == ClientInfo->CallbackWnd.hWnd)
366 return ClientInfo->CallbackWnd.pWnd;
367
369}
#define GetWin32ClientInfo()
Definition: ntuser.h:352
CLIENT_DATA ClientInfo
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

◆ ValidateHwndNoErr()

PWND FASTCALL ValidateHwndNoErr ( HWND  hwnd)

Definition at line 376 of file misc.c.

377{
378 PWND Wnd;
381
382 /* See if the window is cached */
383 if (hwnd == ClientInfo->CallbackWnd.hWnd)
384 return ClientInfo->CallbackWnd.pWnd;
385
387 if (Wnd != NULL)
388 {
389 return Wnd;
390 }
391
392 return NULL;
393}
PVOID FASTCALL ValidateHandleNoErr(HANDLE handle, UINT uType)
Definition: misc.c:310

◆ ValidateHwndOrDesk()

PWND FASTCALL ValidateHwndOrDesk ( HWND  hwnd)

Definition at line 410 of file misc.c.

411{
412 if (hwnd == HWND_DESKTOP)
413 return GetThreadDesktopWnd();
414
415 return ValidateHwnd(hwnd);
416}
#define ValidateHwnd(hwnd)
Definition: precomp.h:85
PWND FASTCALL GetThreadDesktopWnd(VOID)
Definition: misc.c:397
#define HWND_DESKTOP
Definition: winuser.h:1209

◆ WCSToMBEx()

DWORD WINAPI WCSToMBEx ( WORD  CodePage,
LPWSTR  UnicodeString,
LONG  UnicodeSize,
LPSTR MBString,
LONG  MBSize,
BOOL  Allocate 
)

Definition at line 421 of file misc.c.

422{
423 DWORD Size;
424 if (UnicodeSize == -1)
425 {
426 UnicodeSize = wcslen(UnicodeString)+1;
427 }
428 if (MBSize == -1)
429 {
430 if (!Allocate)
431 {
432 return 0;
433 }
434 MBSize = UnicodeSize * 2;
435 }
436 if (Allocate)
437 {
438 LPSTR SafeString = RtlAllocateHeap(GetProcessHeap(), 0, MBSize);
439 if (SafeString == NULL)
440 return 0;
441 *MBString = SafeString;
442 }
443 if (CodePage == 0)
444 {
445 RtlUnicodeToMultiByteN(*MBString,MBSize,&Size,UnicodeString,UnicodeSize);
446 }
447 else
448 {
449 WideCharToMultiByte(CodePage,0,UnicodeString,UnicodeSize,*MBString,MBSize,0,0);
450 }
451 return UnicodeSize;
452}
#define WideCharToMultiByte
Definition: compat.h:111
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:107
char * LPSTR
Definition: xmlstorage.h:182

Variable Documentation

◆ g_ObjectHeapTypeShared

const BOOL g_ObjectHeapTypeShared[TYPE_CTYPES]
static
Initial value:

Definition at line 221 of file misc.c.

Referenced by ValidateHandle(), and ValidateHandleNoErr().