diff --git a/reactos/include/win32k/dc.h b/reactos/include/win32k/dc.h index 167e4ecc858..d244f9faf05 100644 --- a/reactos/include/win32k/dc.h +++ b/reactos/include/win32k/dc.h @@ -86,7 +86,7 @@ typedef struct _DC HSURF Surface; DRIVER_FUNCTIONS DriverFunctions; - PWSTR DriverName; + UNICODE_STRING DriverName; HANDLE DeviceDriver; INT wndOrgX; /* Window origin */ @@ -125,9 +125,9 @@ typedef struct GDIOBJ_UnlockObj ((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC) HDC FASTCALL RetrieveDisplayHDC(VOID); -HDC FASTCALL DC_AllocDC(LPCWSTR Driver); +HDC FASTCALL DC_AllocDC(PUNICODE_STRING Driver); VOID FASTCALL DC_InitDC(HDC DCToInit); -HDC FASTCALL DC_FindOpenDC(LPCWSTR Driver); +HDC FASTCALL DC_FindOpenDC(PUNICODE_STRING Driver); VOID FASTCALL DC_FreeDC(HDC DCToFree); HDC FASTCALL DC_GetNextDC (PDC pDC); VOID FASTCALL DC_SetNextDC (PDC pDC, HDC hNextDC); @@ -141,10 +141,10 @@ BOOL FASTCALL DC_InvertXform(const XFORM *xformSrc, XFORM *xformDest); BOOL STDCALL NtGdiCancelDC(HDC hDC); HDC STDCALL NtGdiCreateCompatableDC(HDC hDC); -HDC STDCALL NtGdiCreateDC(LPCWSTR Driver, - LPCWSTR Device, - LPCWSTR Output, - CONST PDEVMODEW InitData); +HDC STDCALL NtGdiCreateDC(PUNICODE_STRING Driver, + PUNICODE_STRING Device, + PUNICODE_STRING Output, + CONST PDEVMODEW InitData); HDC STDCALL NtGdiCreateIC(LPCWSTR Driver, LPCWSTR Device, LPCWSTR Output, diff --git a/reactos/lib/gdi32/objects/dc.c b/reactos/lib/gdi32/objects/dc.c index 62c0f2075a6..7025d407a36 100644 --- a/reactos/lib/gdi32/objects/dc.c +++ b/reactos/lib/gdi32/objects/dc.c @@ -435,12 +435,19 @@ CreateDCW ( CONST DEVMODEW * lpInitData ) { - return NtGdiCreateDC ( - lpwszDriver, - lpwszDevice, - lpwszOutput, - (PDEVMODEW)lpInitData - ); + UNICODE_STRING Driver, Device, Output; + + if(lpwszDriver) + RtlInitUnicodeString(&Driver, lpwszDriver); + if(lpwszDevice) + RtlInitUnicodeString(&Driver, lpwszDevice); + if(lpwszOutput) + RtlInitUnicodeString(&Driver, lpwszOutput); + + return NtGdiCreateDC((lpwszDriver ? &Driver : NULL), + (lpwszDevice ? &Device : NULL), + (lpwszOutput ? &Output : NULL), + (PDEVMODEW)lpInitData); } diff --git a/reactos/subsys/win32k/include/cleanup.h b/reactos/subsys/win32k/include/cleanup.h index f4f738849bb..bdc5d3a078d 100644 --- a/reactos/subsys/win32k/include/cleanup.h +++ b/reactos/subsys/win32k/include/cleanup.h @@ -3,4 +3,8 @@ NTSTATUS FASTCALL InitCleanupImpl(VOID); +NTSTATUS FASTCALL +IntSafeCopyUnicodeString(PUNICODE_STRING Dest, + PUNICODE_STRING Source); + #endif /* ndef _SUBSYS_WIN32K_INCLUDE_CLEANUP_H */ diff --git a/reactos/subsys/win32k/include/intgdi.h b/reactos/subsys/win32k/include/intgdi.h index fa0e45d1bb4..27e7cdd022c 100644 --- a/reactos/subsys/win32k/include/intgdi.h +++ b/reactos/subsys/win32k/include/intgdi.h @@ -108,5 +108,11 @@ IntGdiGetDCOrgEx(DC *dc, LPPOINT Point); INT FASTCALL IntGdiGetObject(HANDLE handle, INT count, LPVOID buffer); +HDC FASTCALL +IntGdiCreateDC(PUNICODE_STRING Driver, + PUNICODE_STRING Device, + PUNICODE_STRING Output, + CONST PDEVMODEW InitData); + #endif /* _WIN32K_INTGDI_H */ diff --git a/reactos/subsys/win32k/ntuser/misc.c b/reactos/subsys/win32k/ntuser/misc.c index 7a5002404f8..b32a277d96d 100644 --- a/reactos/subsys/win32k/ntuser/misc.c +++ b/reactos/subsys/win32k/ntuser/misc.c @@ -1,4 +1,4 @@ -/* $Id: misc.c,v 1.32 2003/11/30 20:03:47 navaraf Exp $ +/* $Id: misc.c,v 1.33 2003/12/13 15:49:32 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -670,3 +670,40 @@ NtUserGetGuiResources( return Ret; } +NTSTATUS FASTCALL +IntSafeCopyUnicodeString(PUNICODE_STRING Dest, + PUNICODE_STRING Source) +{ + NTSTATUS Status; + PWSTR Src; + + Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING)); + if(!NT_SUCCESS(Status)) + { + return Status; + } + + if(Dest->MaximumLength > 0) + { + Src = Dest->Buffer; + + Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength); + if(!Dest->Buffer) + { + return STATUS_NO_MEMORY; + } + + Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->MaximumLength); + if(!NT_SUCCESS(Status)) + { + ExFreePool(Dest->Buffer); + Dest->Buffer = NULL; + return Status; + } + + + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + diff --git a/reactos/subsys/win32k/ntuser/windc.c b/reactos/subsys/win32k/ntuser/windc.c index 2736e22b27c..f283d1fc3ca 100644 --- a/reactos/subsys/win32k/ntuser/windc.c +++ b/reactos/subsys/win32k/ntuser/windc.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: windc.c,v 1.44 2003/12/12 18:18:21 weiden Exp $ +/* $Id: windc.c,v 1.45 2003/12/13 15:49:32 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -42,6 +42,7 @@ #include #include #include +#include #define NDEBUG #include @@ -127,14 +128,17 @@ DceAllocDCE(HWND hWnd, DCE_TYPE Type) { HDCE DceHandle; DCE* Dce; + UNICODE_STRING DriverName; DceHandle = DCEOBJ_AllocDCE(); if(!DceHandle) return NULL; + RtlInitUnicodeString(&DriverName, L"DISPLAY"); + Dce = DCEOBJ_LockDCE(DceHandle); Dce->Self = DceHandle; - Dce->hDC = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); + Dce->hDC = IntGdiCreateDC(&DriverName, NULL, NULL, NULL); if (NULL == defaultDCstate) { defaultDCstate = NtGdiGetDCState(Dce->hDC); diff --git a/reactos/subsys/win32k/ntuser/winsta.c b/reactos/subsys/win32k/ntuser/winsta.c index 3aeff2cef3d..be977d0b137 100644 --- a/reactos/subsys/win32k/ntuser/winsta.c +++ b/reactos/subsys/win32k/ntuser/winsta.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: winsta.c,v 1.52 2003/12/13 11:34:53 navaraf Exp $ + * $Id: winsta.c,v 1.53 2003/12/13 15:49:32 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -51,6 +51,7 @@ #include #include #include +#include /* Needed for DIRECTORY_OBJECT */ #include @@ -200,11 +201,13 @@ IntGetWindowStationObject(PWINSTATION_OBJECT Object) BOOL FASTCALL IntInitializeDesktopGraphics(VOID) { + UNICODE_STRING DriverName; if (! IntCreatePrimarySurface()) { return FALSE; } - ScreenDeviceContext = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); + RtlInitUnicodeString(&DriverName, L"DISPLAY"); + ScreenDeviceContext = IntGdiCreateDC(&DriverName, NULL, NULL, NULL); if (NULL == ScreenDeviceContext) { IntDestroyPrimarySurface(); diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index 45c4ff4a731..bd2443d0b64 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dc.c,v 1.110 2003/12/13 13:45:18 weiden Exp $ +/* $Id: dc.c,v 1.111 2003/12/13 15:49:32 weiden Exp $ * * DC.C - Device context functions * @@ -50,6 +50,8 @@ #include #include #include +#include +#include #define NDEBUG #include @@ -136,6 +138,7 @@ NtGdiCreateCompatableDC(HDC hDC) HDC hNewDC, DisplayDC; HRGN hVisRgn; BITMAPOBJ *pb; + UNICODE_STRING DriverName; DisplayDC = NULL; if (hDC == NULL) @@ -143,7 +146,8 @@ NtGdiCreateCompatableDC(HDC hDC) hDC = IntGetScreenDC(); if (NULL == hDC) { - DisplayDC = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); + RtlInitUnicodeString(&DriverName, L"DISPLAY"); + DisplayDC = IntGdiCreateDC(&DriverName, NULL, NULL, NULL); if (NULL == DisplayDC) { return NULL; @@ -162,7 +166,7 @@ NtGdiCreateCompatableDC(HDC hDC) } return NULL; } - hNewDC = DC_AllocDC(OrigDC->DriverName); + hNewDC = DC_AllocDC(&OrigDC->DriverName); if (NULL == hNewDC) { @@ -660,19 +664,22 @@ IntDestroyPrimarySurface() ObDereferenceObject(PrimarySurface.VideoFileObject); } -HDC STDCALL -NtGdiCreateDC(LPCWSTR Driver, - LPCWSTR Device, - LPCWSTR Output, - CONST PDEVMODEW InitData) +HDC FASTCALL +IntGdiCreateDC(PUNICODE_STRING Driver, + PUNICODE_STRING Device, + PUNICODE_STRING Output, + CONST PDEVMODEW InitData) { HDC hNewDC; PDC NewDC; HDC hDC = NULL; PSURFGDI SurfGDI; HRGN hVisRgn; - - if (NULL == Driver || 0 == _wcsicmp(Driver, L"DISPLAY")) + UNICODE_STRING StdDriver; + + RtlInitUnicodeString(&StdDriver, L"DISPLAY"); + + if (NULL == Driver || 0 == RtlCompareUnicodeString(Driver, &StdDriver, TRUE)) { if (! IntGraphicsCheck(TRUE)) { @@ -740,10 +747,58 @@ NtGdiCreateDC(LPCWSTR Driver, NtGdiSetTextAlign(hNewDC, TA_TOP); NtGdiSetBkColor(hNewDC, RGB(255, 255, 255)); NtGdiSetBkMode(hNewDC, OPAQUE); - + return hNewDC; } +HDC STDCALL +NtGdiCreateDC(PUNICODE_STRING Driver, + PUNICODE_STRING Device, + PUNICODE_STRING Output, + CONST PDEVMODEW InitData) +{ + UNICODE_STRING SafeDriver, SafeDevice; + DEVMODEW SafeInitData; + HDC Ret; + NTSTATUS Status; + + if(InitData) + { + Status = MmCopyFromCaller(&SafeInitData, InitData, sizeof(DEVMODEW)); + if(!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + return NULL; + } + /* FIXME - InitData can have some more bytes! */ + } + + if(Driver) + { + Status = IntSafeCopyUnicodeString(&SafeDriver, Driver); + if(!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + return NULL; + } + } + + if(Device) + { + Status = IntSafeCopyUnicodeString(&SafeDevice, Device); + if(!NT_SUCCESS(Status)) + { + RtlFreeUnicodeString(&SafeDriver); + SetLastNtError(Status); + return NULL; + } + } + + Ret = IntGdiCreateDC(&SafeDriver, &SafeDevice, NULL, &SafeInitData); + + return Ret; +} + HDC STDCALL NtGdiCreateIC(LPCWSTR Driver, LPCWSTR Device, @@ -751,7 +806,8 @@ NtGdiCreateIC(LPCWSTR Driver, CONST PDEVMODEW DevMode) { /* FIXME: this should probably do something else... */ - return NtGdiCreateDC(Driver, Device, Output, DevMode); + //return NtGdiCreateDC(Driver, Device, Output, DevMode); + return NULL; } BOOL STDCALL @@ -1837,23 +1893,38 @@ DC_SET_MODE( NtGdiSetStretchBltMode, w.stretchBltMode, BLACKONWHITE, HALFTONE ) // ---------------------------------------------------- Private Interface HDC FASTCALL -DC_AllocDC(LPCWSTR Driver) +DC_AllocDC(PUNICODE_STRING Driver) { PDC NewDC; HDC hDC; + PWSTR Buf = NULL; + + if (Driver != NULL) + { + Buf = ExAllocatePoolWithTag(PagedPool, Driver->MaximumLength, TAG_DC); + if(!Buf) + { + return NULL; + } + RtlCopyMemory(Buf, Driver->Buffer, Driver->MaximumLength); + } hDC = (HDC) GDIOBJ_AllocObj(sizeof(DC), GDI_OBJECT_TYPE_DC, (GDICLEANUPPROC) DC_InternalDeleteDC); if (hDC == NULL) { + if(Buf) + { + ExFreePool(Buf); + } return NULL; } NewDC = DC_LockDc(hDC); - + if (Driver != NULL) { - NewDC->DriverName = ExAllocatePoolWithTag(PagedPool, (wcslen(Driver) + 1) * sizeof(WCHAR), TAG_DC); - wcscpy(NewDC->DriverName, Driver); + RtlCopyMemory(&NewDC->DriverName, Driver, sizeof(UNICODE_STRING)); + NewDC->DriverName.Buffer = Buf; } NewDC->w.xformWorld2Wnd.eM11 = 1.0f; @@ -1875,7 +1946,7 @@ DC_AllocDC(LPCWSTR Driver) } HDC FASTCALL -DC_FindOpenDC(LPCWSTR Driver) +DC_FindOpenDC(PUNICODE_STRING Driver) { return NULL; } @@ -1909,11 +1980,7 @@ BOOL FASTCALL DC_InternalDeleteDC( PDC DCToDelete ) { - if (NULL != DCToDelete->DriverName) - { - ExFreePool(DCToDelete->DriverName); - } - + RtlFreeUnicodeString(&DCToDelete->DriverName); return TRUE; }