mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
- Rewrite David Welch's Ansi function wrappers to reduce their code size, improve readability, and fix a bug of freeing of a non-allocated string. Spotted by Christoph vW.
svn path=/trunk/; revision=34096
This commit is contained in:
parent
00334059ac
commit
968033dd41
2 changed files with 65 additions and 66 deletions
|
@ -468,35 +468,34 @@ CreateDesktopA(LPCSTR lpszDesktop,
|
|||
ACCESS_MASK dwDesiredAccess,
|
||||
LPSECURITY_ATTRIBUTES lpsa)
|
||||
{
|
||||
ANSI_STRING DesktopNameA;
|
||||
UNICODE_STRING DesktopNameU;
|
||||
HDESK hDesktop;
|
||||
LPDEVMODEW DevmodeW = NULL;
|
||||
UNICODE_STRING DesktopNameU;
|
||||
HDESK hDesktop;
|
||||
LPDEVMODEW DevmodeW = NULL;
|
||||
|
||||
if (lpszDesktop != NULL)
|
||||
if (lpszDesktop)
|
||||
{
|
||||
RtlInitAnsiString(&DesktopNameA, (LPSTR)lpszDesktop);
|
||||
RtlAnsiStringToUnicodeString(&DesktopNameU, &DesktopNameA, TRUE);
|
||||
/* After conversion, the buffer is zero-terminated */
|
||||
RtlCreateUnicodeStringFromAsciiz(&DesktopNameU, lpszDesktop);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&DesktopNameU, NULL);
|
||||
RtlInitUnicodeString(&DesktopNameU, NULL);
|
||||
}
|
||||
|
||||
if (pDevmode)
|
||||
{
|
||||
DevmodeW = GdiConvertToDevmodeW(pDevmode);
|
||||
}
|
||||
if (pDevmode)
|
||||
DevmodeW = GdiConvertToDevmodeW(pDevmode);
|
||||
|
||||
hDesktop = CreateDesktopW(DesktopNameU.Buffer,
|
||||
NULL,
|
||||
DevmodeW,
|
||||
dwFlags,
|
||||
dwDesiredAccess,
|
||||
lpsa);
|
||||
hDesktop = CreateDesktopW(DesktopNameU.Buffer,
|
||||
NULL,
|
||||
DevmodeW,
|
||||
dwFlags,
|
||||
dwDesiredAccess,
|
||||
lpsa);
|
||||
|
||||
RtlFreeUnicodeString(&DesktopNameU);
|
||||
return(hDesktop);
|
||||
/* Free the string, if it was allocated */
|
||||
if (lpszDesktop) RtlFreeUnicodeString(&DesktopNameU);
|
||||
|
||||
return hDesktop;
|
||||
}
|
||||
|
||||
|
||||
|
@ -580,26 +579,28 @@ OpenDesktopA(
|
|||
BOOL fInherit,
|
||||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
ANSI_STRING DesktopNameA;
|
||||
UNICODE_STRING DesktopNameU;
|
||||
HDESK hDesktop;
|
||||
UNICODE_STRING DesktopNameU;
|
||||
HDESK hDesktop;
|
||||
|
||||
if (lpszDesktop != NULL) {
|
||||
RtlInitAnsiString(&DesktopNameA, lpszDesktop);
|
||||
RtlAnsiStringToUnicodeString(&DesktopNameU, &DesktopNameA, TRUE);
|
||||
} else {
|
||||
RtlInitUnicodeString(&DesktopNameU, NULL);
|
||||
}
|
||||
if (lpszDesktop)
|
||||
{
|
||||
/* After conversion, the buffer is zero-terminated */
|
||||
RtlCreateUnicodeStringFromAsciiz(&DesktopNameU, lpszDesktop);
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&DesktopNameU, NULL);
|
||||
}
|
||||
|
||||
hDesktop = OpenDesktopW(
|
||||
DesktopNameU.Buffer,
|
||||
dwFlags,
|
||||
fInherit,
|
||||
dwDesiredAccess);
|
||||
hDesktop = OpenDesktopW(DesktopNameU.Buffer,
|
||||
dwFlags,
|
||||
fInherit,
|
||||
dwDesiredAccess);
|
||||
|
||||
RtlFreeUnicodeString(&DesktopNameU);
|
||||
/* Free the string, if it was allocated */
|
||||
if (lpszDesktop) RtlFreeUnicodeString(&DesktopNameU);
|
||||
|
||||
return hDesktop;
|
||||
return hDesktop;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,29 +32,28 @@ CreateWindowStationA(LPSTR lpwinsta,
|
|||
ACCESS_MASK dwDesiredAccess,
|
||||
LPSECURITY_ATTRIBUTES lpsa)
|
||||
{
|
||||
ANSI_STRING WindowStationNameA;
|
||||
UNICODE_STRING WindowStationNameU;
|
||||
HWINSTA hWinSta;
|
||||
UNICODE_STRING WindowStationNameU;
|
||||
HWINSTA hWinSta;
|
||||
|
||||
if (lpwinsta != NULL)
|
||||
if (lpwinsta)
|
||||
{
|
||||
RtlInitAnsiString(&WindowStationNameA, lpwinsta);
|
||||
RtlAnsiStringToUnicodeString(&WindowStationNameU, &WindowStationNameA,
|
||||
TRUE);
|
||||
/* After conversion, the buffer is zero-terminated */
|
||||
RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU, lpwinsta);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&WindowStationNameU, NULL);
|
||||
RtlInitUnicodeString(&WindowStationNameU, NULL);
|
||||
}
|
||||
|
||||
hWinSta = CreateWindowStationW(WindowStationNameU.Buffer,
|
||||
dwReserved,
|
||||
dwDesiredAccess,
|
||||
lpsa);
|
||||
hWinSta = CreateWindowStationW(WindowStationNameU.Buffer,
|
||||
dwReserved,
|
||||
dwDesiredAccess,
|
||||
lpsa);
|
||||
|
||||
RtlFreeUnicodeString(&WindowStationNameU);
|
||||
/* Free the string, if it was allocated */
|
||||
if (lpwinsta) RtlFreeUnicodeString(&WindowStationNameU);
|
||||
|
||||
return hWinSta;
|
||||
return hWinSta;
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,28 +290,27 @@ OpenWindowStationA(LPSTR lpszWinSta,
|
|||
BOOL fInherit,
|
||||
ACCESS_MASK dwDesiredAccess)
|
||||
{
|
||||
ANSI_STRING WindowStationNameA;
|
||||
UNICODE_STRING WindowStationNameU;
|
||||
HWINSTA hWinSta;
|
||||
UNICODE_STRING WindowStationNameU;
|
||||
HWINSTA hWinSta;
|
||||
|
||||
if (lpszWinSta != NULL)
|
||||
if (lpszWinSta)
|
||||
{
|
||||
RtlInitAnsiString(&WindowStationNameA, lpszWinSta);
|
||||
RtlAnsiStringToUnicodeString(&WindowStationNameU, &WindowStationNameA,
|
||||
TRUE);
|
||||
/* After conversion, the buffer is zero-terminated */
|
||||
RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU, lpszWinSta);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
RtlInitUnicodeString(&WindowStationNameU, NULL);
|
||||
RtlInitUnicodeString(&WindowStationNameU, NULL);
|
||||
}
|
||||
|
||||
hWinSta = OpenWindowStationW(WindowStationNameU.Buffer,
|
||||
fInherit,
|
||||
dwDesiredAccess);
|
||||
hWinSta = OpenWindowStationW(WindowStationNameU.Buffer,
|
||||
fInherit,
|
||||
dwDesiredAccess);
|
||||
|
||||
RtlFreeUnicodeString(&WindowStationNameU);
|
||||
/* Free the string, if it was allocated */
|
||||
if (lpszWinSta) RtlFreeUnicodeString(&WindowStationNameU);
|
||||
|
||||
return hWinSta;
|
||||
return hWinSta;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue