2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Video initialization and display settings
5 * FILE: subsystems/win32/win32k/ntuser/display.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@reactos.org)
20 static const PWCHAR KEY_ROOT
= L
"";
21 static const PWCHAR KEY_VIDEO
= L
"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO";
24 RegWriteDisplaySettings(HKEY hkey
, PDEVMODEW pdm
)
26 RegWriteDWORD(hkey
, L
"DefaultSettings.BitsPerPel", pdm
->dmBitsPerPel
);
27 RegWriteDWORD(hkey
, L
"DefaultSettings.XResolution", pdm
->dmPelsWidth
);
28 RegWriteDWORD(hkey
, L
"DefaultSettings.YResolution", pdm
->dmPelsHeight
);
29 RegWriteDWORD(hkey
, L
"DefaultSettings.Flags", pdm
->dmDisplayFlags
);
30 RegWriteDWORD(hkey
, L
"DefaultSettings.VRefresh", pdm
->dmDisplayFrequency
);
31 RegWriteDWORD(hkey
, L
"DefaultSettings.XPanning", pdm
->dmPanningWidth
);
32 RegWriteDWORD(hkey
, L
"DefaultSettings.YPanning", pdm
->dmPanningHeight
);
33 RegWriteDWORD(hkey
, L
"DefaultSettings.Orientation", pdm
->dmDisplayOrientation
);
34 RegWriteDWORD(hkey
, L
"DefaultSettings.FixedOutput", pdm
->dmDisplayFixedOutput
);
35 RegWriteDWORD(hkey
, L
"Attach.RelativeX", pdm
->dmPosition
.x
);
36 RegWriteDWORD(hkey
, L
"Attach.RelativeY", pdm
->dmPosition
.y
);
37 // RegWriteDWORD(hkey, L"Attach.ToDesktop, pdm->dmBitsPerPel", pdm->);
41 RegReadDisplaySettings(HKEY hkey
, PDEVMODEW pdm
)
45 /* Zero out the structure */
46 RtlZeroMemory(pdm
, sizeof(DEVMODEW
));
49 #define READ(field, str, flag) \
50 if (RegReadDWORD(hkey, L##str, &dwValue)) \
52 pdm->field = dwValue; \
53 pdm->dmFields |= flag; \
56 /* Read all present settings */
57 READ(dmBitsPerPel
, "DefaultSettings.BitsPerPel", DM_BITSPERPEL
);
58 READ(dmPelsWidth
, "DefaultSettings.XResolution", DM_PELSWIDTH
);
59 READ(dmPelsHeight
, "DefaultSettings.YResolution", DM_PELSHEIGHT
);
60 READ(dmDisplayFlags
, "DefaultSettings.Flags", DM_DISPLAYFLAGS
);
61 READ(dmDisplayFrequency
, "DefaultSettings.VRefresh", DM_DISPLAYFREQUENCY
);
62 READ(dmPanningWidth
, "DefaultSettings.XPanning", DM_PANNINGWIDTH
);
63 READ(dmPanningHeight
, "DefaultSettings.YPanning", DM_PANNINGHEIGHT
);
64 READ(dmDisplayOrientation
, "DefaultSettings.Orientation", DM_DISPLAYORIENTATION
);
65 READ(dmDisplayFixedOutput
, "DefaultSettings.FixedOutput", DM_DISPLAYFIXEDOUTPUT
);
66 READ(dmPosition
.x
, "Attach.RelativeX", DM_POSITION
);
67 READ(dmPosition
.y
, "Attach.RelativeY", DM_POSITION
);
73 IN PWSTR pwszDeviceName
,
76 PGRAPHICS_DEVICE pGraphicsDevice
;
77 UNICODE_STRING ustrDeviceName
, ustrDisplayDrivers
, ustrDescription
;
84 DPRINT1("InitDisplayDriver(%S, %S);\n",
85 pwszDeviceName
, pwszRegKey
);
87 /* Open the driver's registry key */
88 Status
= RegOpenKey(pwszRegKey
, &hkey
);
89 if (!NT_SUCCESS(Status
))
91 DPRINT1("Failed to open registry key: %ls\n", pwszRegKey
);
95 /* Query the diplay drivers */
96 cbSize
= sizeof(awcBuffer
) - 10;
97 Status
= RegQueryValue(hkey
,
98 L
"InstalledDisplayDrivers",
102 if (!NT_SUCCESS(Status
))
104 DPRINT1("Didn't find 'InstalledDisplayDrivers', status = 0x%lx\n", Status
);
109 /* Initialize the UNICODE_STRING */
110 ustrDisplayDrivers
.Buffer
= awcBuffer
;
111 ustrDisplayDrivers
.MaximumLength
= cbSize
;
112 ustrDisplayDrivers
.Length
= cbSize
;
114 /* Set Buffer for description and size of remaining buffer */
115 ustrDescription
.Buffer
= awcBuffer
+ (cbSize
/ sizeof(WCHAR
));
116 cbSize
= sizeof(awcBuffer
) - cbSize
;
118 /* Query the device string */
119 Status
= RegQueryValue(hkey
,
120 L
"Device Description",
122 ustrDescription
.Buffer
,
124 if (NT_SUCCESS(Status
))
126 ustrDescription
.MaximumLength
= cbSize
;
127 ustrDescription
.Length
= cbSize
;
131 RtlInitUnicodeString(&ustrDescription
, L
"<unknown>");
134 /* Query the default settings */
135 RegReadDisplaySettings(hkey
, &dmDefault
);
137 /* Close the registry key */
140 /* Register the device with GDI */
141 RtlInitUnicodeString(&ustrDeviceName
, pwszDeviceName
);
142 pGraphicsDevice
= EngpRegisterGraphicsDevice(&ustrDeviceName
,
147 return pGraphicsDevice
;
152 PUNICODE_STRING pustrRegPath
,
155 ULONG iDevNum
, iVGACompatible
= -1, ulMaxObjectNumber
= 0;
156 WCHAR awcDeviceName
[20];
157 WCHAR awcBuffer
[256];
159 PGRAPHICS_DEVICE pGraphicsDevice
;
163 DPRINT1("----------------------------- InitVideo() -------------------------------\n");
165 Status
= RegOpenKey(L
"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control", &hkey
);
166 if (NT_SUCCESS(Status
))
169 Status
= RegQueryValue(hkey
, L
"SystemStartOptions", REG_SZ
, awcBuffer
, &cbValue
);
170 if (NT_SUCCESS(Status
))
172 /* Check if VGA mode is requested. */
173 if (wcsstr(awcBuffer
, L
"/BASEVIDEO") != 0)
175 DPRINT1("VGA mode requested.\n");
183 /* Open the key for the adapters */
184 Status
= RegOpenKey(KEY_VIDEO
, &hkey
);
185 if (!NT_SUCCESS(Status
))
187 DPRINT1("Could not open device registry key!\n");
191 /* Read the name of the VGA adapter */
193 Status
= RegQueryValue(hkey
, L
"VgaCompatible", REG_SZ
, awcDeviceName
, &cbValue
);
194 if (NT_SUCCESS(Status
))
196 iVGACompatible
= _wtoi(&awcDeviceName
[13]);
197 DPRINT1("VGA adapter = %ld\n", iVGACompatible
);
200 /* Get the maximum mumber of adapters */
201 if (!RegReadDWORD(hkey
, L
"MaxObjectNumber", &ulMaxObjectNumber
))
203 DPRINT1("Could not read MaxObjectNumber, defaulting to 0.\n");
206 DPRINT("Found %ld devices\n", ulMaxObjectNumber
);
208 /* Loop through all adapters */
210 for (iDevNum
= 0; iDevNum
<= ulMaxObjectNumber
; iDevNum
++)
212 /* Create the adapter's key name */
213 swprintf(awcDeviceName
, L
"\\Device\\Video%lu", iDevNum
);
215 /* Read the reg key name */
216 Status
= RegQueryValue(hkey
, awcDeviceName
, REG_SZ
, awcBuffer
, &cbValue
);
218 pGraphicsDevice
= InitDisplayDriver(awcDeviceName
, awcBuffer
);
220 /* Check if this is the VGA adapter */
221 if (iDevNum
== iVGACompatible
)
223 /* Set the VGA device as primary */
224 gpVgaGraphicsDevice
= pGraphicsDevice
;
225 DPRINT1("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice
);
228 /* Set the first one as primary device */
229 if (!gpPrimaryGraphicsDevice
)
230 gpPrimaryGraphicsDevice
= pGraphicsDevice
;
237 if (gpVgaGraphicsDevice
)
239 /* Set the VgaAdapter as primary */
240 gpPrimaryGraphicsDevice
= gpVgaGraphicsDevice
;
245 DPRINT1("Could not find VGA compatible driver. Trying normal.\n");
256 UserEnumDisplayDevices(
257 PUNICODE_STRING pustrDevice
,
259 PDISPLAY_DEVICEW pdispdev
,
262 PGRAPHICS_DEVICE pGraphicsDevice
;
267 /* Ask gdi for the GRAPHICS_DEVICE */
268 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, iDevNum
, 0);
269 if (!pGraphicsDevice
)
271 /* No device found */
272 DPRINT1("No GRAPHICS_DEVICE found\n");
273 return STATUS_UNSUCCESSFUL
;
276 /* Open thhe device map registry key */
277 Status
= RegOpenKey(KEY_VIDEO
, &hkey
);
278 if (!NT_SUCCESS(Status
))
280 /* No device found */
281 DPRINT1("Could not open reg key\n");
282 return STATUS_UNSUCCESSFUL
;
285 /* Query the registry path */
286 cbSize
= sizeof(pdispdev
->DeviceKey
);
288 pGraphicsDevice
->szNtDeviceName
,
293 /* Close registry key */
296 /* Copy device name, device string and StateFlags */
297 wcsncpy(pdispdev
->DeviceName
, pGraphicsDevice
->szWinDeviceName
, 32);
298 wcsncpy(pdispdev
->DeviceString
, pGraphicsDevice
->pwszDescription
, 128);
299 pdispdev
->StateFlags
= pGraphicsDevice
->StateFlags
;
301 // FIXME: fill in DEVICE ID
303 return STATUS_SUCCESS
;
309 NtUserEnumDisplayDevices(
310 PUNICODE_STRING pustrDevice
,
312 PDISPLAY_DEVICEW pDisplayDevice
,
315 UNICODE_STRING ustrDevice
;
316 WCHAR awcDevice
[CCHDEVICENAME
];
317 DISPLAY_DEVICEW dispdev
;
320 DPRINT("Enter NtUserEnumDisplayDevices(%wZ, %ld)\n",
321 pustrDevice
, iDevNum
);
323 // FIXME: HACK, desk.cpl passes broken crap
324 if (pustrDevice
&& iDevNum
!= 0)
327 dispdev
.cb
= sizeof(DISPLAY_DEVICEW
);
331 /* Initialize destination string */
332 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
336 /* Probe the UNICODE_STRING and the buffer */
337 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
338 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
340 /* Copy the string */
341 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
343 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
345 // _SEH2_YIELD(return _SEH2_GetExceptionCode());
346 _SEH2_YIELD(return NT_SUCCESS(_SEH2_GetExceptionCode()));
350 if (ustrDevice
.Length
> 0)
351 pustrDevice
= &ustrDevice
;
356 /* Acquire global USER lock */
357 UserEnterExclusive();
359 /* Call the internal function */
360 Status
= UserEnumDisplayDevices(pustrDevice
, iDevNum
, &dispdev
, dwFlags
);
365 /* On success copy data to caller */
366 if (NT_SUCCESS(Status
))
371 /* First probe the cb field */
372 ProbeForWrite(&pDisplayDevice
->cb
, sizeof(DWORD
), 1);
374 /* Check the buffer size */
375 if (pDisplayDevice
->cb
)
377 /* Probe the output buffer */
378 pDisplayDevice
->cb
= min(pDisplayDevice
->cb
, sizeof(dispdev
));
379 ProbeForWrite(pDisplayDevice
, pDisplayDevice
->cb
, 1);
381 /* Copy as much as the given buffer allows */
382 RtlCopyMemory(pDisplayDevice
, &dispdev
, pDisplayDevice
->cb
);
385 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
387 Status
= _SEH2_GetExceptionCode();
392 DPRINT1("Leave NtUserEnumDisplayDevices, Status = 0x%lx\n", Status
);
393 /* Return the result */
395 return NT_SUCCESS(Status
); // FIXME
400 UserEnumCurrentDisplaySettings(
401 PUNICODE_STRING pustrDevice
,
406 /* Get the PDEV for the device */
407 ppdev
= EngpGetPDEV(pustrDevice
);
410 /* No device found */
411 DPRINT1("No PDEV found!\n");
412 return STATUS_UNSUCCESSFUL
;
415 *ppdm
= ppdev
->pdmwDev
;
416 PDEVOBJ_vRelease(ppdev
);
418 return STATUS_SUCCESS
;
423 UserEnumDisplaySettings(
424 PUNICODE_STRING pustrDevice
,
429 PGRAPHICS_DEVICE pGraphicsDevice
;
430 PDEVMODEENTRY pdmentry
;
433 DPRINT("Enter UserEnumDisplaySettings('%ls', %ld)\n",
434 pustrDevice
? pustrDevice
->Buffer
: NULL
, iModeNum
);
436 /* Ask gdi for the GRAPHICS_DEVICE */
437 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, 0, 0);
439 if (!pGraphicsDevice
)
441 /* No device found */
442 DPRINT1("No device found!\n");
443 return STATUS_UNSUCCESSFUL
;
446 if (iModeNum
>= pGraphicsDevice
->cDevModes
)
447 return STATUS_NO_MORE_ENTRIES
;
450 for (i
= 0; i
< pGraphicsDevice
->cDevModes
; i
++)
452 pdmentry
= &pGraphicsDevice
->pDevModeList
[i
];
454 /* FIXME: consider EDS_RAWMODE */
456 if ((!(dwFlags
& EDS_RAWMODE
) && (pdmentry
->dwFlags
& 1)) ||!
457 (dwFlags
& EDS_RAWMODE
))
460 /* Is this the one we want? */
461 if (iFoundMode
== iModeNum
)
463 *ppdm
= pdmentry
->pdm
;
464 return STATUS_SUCCESS
;
467 /* Increment number of found modes */
472 /* Nothing was found */
473 return STATUS_INVALID_PARAMETER
;
478 UserOpenDisplaySettingsKey(
480 IN PUNICODE_STRING pustrDevice
,
484 DISPLAY_DEVICEW dispdev
;
487 /* Get device info */
488 Status
= UserEnumDisplayDevices(pustrDevice
, 0, &dispdev
, 0);
489 if (!NT_SUCCESS(Status
))
494 // FIXME: need to fix the registry key somehow
497 /* Open the registry key */
498 Status
= RegOpenKey(dispdev
.DeviceKey
, &hkey
);
499 if (!NT_SUCCESS(Status
))
509 UserEnumRegistryDisplaySettings(
510 IN PUNICODE_STRING pustrDevice
,
514 NTSTATUS Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, 0);
515 if(NT_SUCCESS(Status
))
517 RegReadDisplaySettings(hkey
, pdm
);
519 return STATUS_SUCCESS
;
527 NtUserEnumDisplaySettings(
528 IN PUNICODE_STRING pustrDevice
,
530 OUT LPDEVMODEW lpDevMode
,
533 UNICODE_STRING ustrDevice
;
534 WCHAR awcDevice
[CCHDEVICENAME
];
536 ULONG cbSize
, cbExtra
;
537 DEVMODEW dmReg
, *pdm
;
539 DPRINT1("Enter NtUserEnumDisplaySettings(%ls, %ld)\n",
540 pustrDevice
? pustrDevice
->Buffer
: 0, iModeNum
);
544 /* Initialize destination string */
545 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
549 /* Probe the UNICODE_STRING and the buffer */
550 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
551 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
553 /* Copy the string */
554 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
556 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
558 _SEH2_YIELD(return _SEH2_GetExceptionCode());
562 pustrDevice
= &ustrDevice
;
565 /* Acquire global USER lock */
566 UserEnterExclusive();
568 if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
570 /* Get the registry settings */
571 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dmReg
);
574 else if (iModeNum
== ENUM_CURRENT_SETTINGS
)
576 /* Get the current settings */
577 Status
= UserEnumCurrentDisplaySettings(pustrDevice
, &pdm
);
581 /* Get specified settings */
582 Status
= UserEnumDisplaySettings(pustrDevice
, iModeNum
, &pdm
, dwFlags
);
588 /* Did we succeed? */
589 if (NT_SUCCESS(Status
))
591 /* Copy some information back */
594 ProbeForRead(lpDevMode
, sizeof(DEVMODEW
), 1);
595 cbSize
= lpDevMode
->dmSize
;
596 cbExtra
= lpDevMode
->dmDriverExtra
;
598 ProbeForWrite(lpDevMode
, cbSize
+ cbExtra
, 1);
599 /* Output what we got */
600 RtlCopyMemory(lpDevMode
, pdm
, min(cbSize
, pdm
->dmSize
));
602 /* output private/extra driver data */
603 if (cbExtra
> 0 && pdm
->dmDriverExtra
> 0)
605 RtlCopyMemory((PCHAR
)lpDevMode
+ cbSize
,
606 (PCHAR
)pdm
+ pdm
->dmSize
,
607 min(cbExtra
, pdm
->dmDriverExtra
));
610 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
612 Status
= _SEH2_GetExceptionCode();
620 BOOL APIENTRY
UserClipCursor(RECTL
*prcl
);
621 VOID APIENTRY
UserRedrawDesktop();
622 HCURSOR FASTCALL
UserSetCursor(PCURICON_OBJECT NewCursor
, BOOL ForceChange
);
626 UserChangeDisplaySettings(
627 PUNICODE_STRING pustrDevice
,
634 LONG lResult
= DISP_CHANGE_SUCCESSFUL
;
640 /* If no DEVMODE is given, use registry settings */
643 /* Get the registry settings */
644 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dm
);
645 if (!NT_SUCCESS(Status
))
647 DPRINT1("Could not load registry settings\n");
648 return DISP_CHANGE_BADPARAM
;
651 else if (pdm
->dmSize
< FIELD_OFFSET(DEVMODEW
, dmFields
))
652 return DISP_CHANGE_BADMODE
; /* This is what winXP SP3 returns */
657 if ((dm
.dmFields
& (DM_PELSWIDTH
| DM_PELSHEIGHT
)) != (DM_PELSWIDTH
| DM_PELSHEIGHT
))
659 DPRINT1("devmode doesn't specify the resolution.\n");
660 return DISP_CHANGE_BADMODE
;
664 ppdev
= EngpGetPDEV(pustrDevice
);
667 DPRINT1("failed to get PDEV\n");
668 return DISP_CHANGE_BADPARAM
;
672 if(dm
.dmBitsPerPel
== 0 || !(dm
.dmFields
& DM_BITSPERPEL
))
674 dm
.dmBitsPerPel
= ppdev
->pdmwDev
->dmBitsPerPel
;
675 dm
.dmFields
|= DM_BITSPERPEL
;
678 if((dm
.dmFields
& DM_DISPLAYFREQUENCY
) && (dm
.dmDisplayFrequency
== 0))
679 dm
.dmDisplayFrequency
= ppdev
->pdmwDev
->dmDisplayFrequency
;
681 /* Look for the requested DEVMODE */
682 pdm
= PDEVOBJ_pdmMatchDevMode(ppdev
, &dm
);
685 DPRINT1("Could not find a matching DEVMODE\n");
686 lResult
= DISP_CHANGE_BADMODE
;
689 else if (flags
& CDS_TEST
)
691 /* It's possible, go ahead! */
692 lResult
= DISP_CHANGE_SUCCESSFUL
;
696 /* Shall we update the registry? */
697 if (flags
& CDS_UPDATEREGISTRY
)
699 /* Open the local or global settings key */
700 Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, flags
& CDS_GLOBAL
);
701 if (NT_SUCCESS(Status
))
703 /* Store the settings */
704 RegWriteDisplaySettings(hkey
, pdm
);
706 /* Close the registry key */
711 DPRINT1("Could not open registry key\n");
712 lResult
= DISP_CHANGE_NOTUPDATED
;
716 /* Check if DEVMODE matches the current mode */
717 if (pdm
== ppdev
->pdmwDev
&& !(flags
& CDS_RESET
))
719 DPRINT1("DEVMODE matches, nothing to do\n");
723 /* Shall we apply the settings? */
724 if (!(flags
& CDS_NORESET
))
728 /* Remove mouse pointer */
729 UserSetCursor(NULL
, TRUE
);
731 /* Do the mode switch */
732 ulResult
= PDEVOBJ_bSwitchMode(ppdev
, pdm
);
734 /* Restore mouse pointer, no hooks called */
735 UserSetCursorPos(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
, FALSE
);
737 /* Check for failure */
740 DPRINT1("failed to set mode\n");
741 lResult
= (lResult
== DISP_CHANGE_NOTUPDATED
) ?
742 DISP_CHANGE_FAILED
: DISP_CHANGE_RESTART
;
747 /* Update the system metrics */
750 //IntvGetDeviceCaps(&PrimarySurface, &GdiHandleTable->DevCaps);
752 /* Remove all cursor clipping */
753 UserClipCursor(NULL
);
755 pdesk
= IntGetActiveDesktop();
756 //IntHideDesktop(pdesk);
758 /* Send WM_DISPLAYCHANGE to all toplevel windows */
759 co_IntSendMessageTimeout(HWND_BROADCAST
,
761 (WPARAM
)ppdev
->gdiinfo
.cBitsPixel
,
762 (LPARAM
)(ppdev
->gdiinfo
.ulHorzRes
+ (ppdev
->gdiinfo
.ulVertRes
<< 16)),
767 //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
773 /* Release the PDEV */
774 PDEVOBJ_vRelease(ppdev
);
781 NtUserChangeDisplaySettings(
782 PUNICODE_STRING pustrDevice
,
783 LPDEVMODEW lpDevMode
,
788 WCHAR awcDevice
[CCHDEVICENAME
];
789 UNICODE_STRING ustrDevice
;
793 /* Check arguments */
794 if ((dwflags
!= CDS_VIDEOPARAMETERS
&& lParam
!= NULL
) ||
797 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
798 return DISP_CHANGE_BADPARAM
;
802 if ((dwflags
& (CDS_GLOBAL
|CDS_NORESET
)) && !(dwflags
& CDS_UPDATEREGISTRY
))
804 return DISP_CHANGE_BADFLAGS
;
807 /* Copy the device name */
810 /* Initialize destination string */
811 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
815 /* Probe the UNICODE_STRING and the buffer */
816 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
817 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
819 /* Copy the string */
820 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
822 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
824 /* Set and return error */
825 SetLastNtError(_SEH2_GetExceptionCode());
826 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
830 pustrDevice
= &ustrDevice
;
838 /* Probe the size field of the structure */
839 ProbeForRead(lpDevMode
, sizeof(dmLocal
.dmSize
), 1);
841 /* Calculate usable size */
842 dmLocal
.dmSize
= min(sizeof(dmLocal
), lpDevMode
->dmSize
);
844 /* Probe and copy the full DEVMODE */
845 ProbeForRead(lpDevMode
, dmLocal
.dmSize
, 1);
846 RtlCopyMemory(&dmLocal
, lpDevMode
, dmLocal
.dmSize
);
848 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
850 /* Set and return error */
851 SetLastNtError(_SEH2_GetExceptionCode());
852 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
856 /* Check for extra parameters */
857 if (dmLocal
.dmDriverExtra
> 0)
860 DPRINT1("lpDevMode->dmDriverExtra is IGNORED!\n");
861 dmLocal
.dmDriverExtra
= 0;
864 /* Use the local structure */
865 lpDevMode
= &dmLocal
;
868 // FIXME: Copy videoparameters
870 /* Acquire global USER lock */
871 UserEnterExclusive();
873 /* Call internal function */
874 lRet
= UserChangeDisplaySettings(pustrDevice
, lpDevMode
, hwnd
, dwflags
, NULL
);