diff --git a/reactos/lib/user32/windows/clipboard.c b/reactos/lib/user32/windows/clipboard.c index dfb0e8e2021..fa5105ea25d 100644 --- a/reactos/lib/user32/windows/clipboard.c +++ b/reactos/lib/user32/windows/clipboard.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: clipboard.c,v 1.7 2003/12/14 13:26:20 weiden Exp $ +/* $Id: clipboard.c,v 1.8 2003/12/14 13:55:01 weiden Exp $ * * PROJECT: ReactOS user32.dll * FILE: lib/user32/windows/input.c @@ -106,6 +106,9 @@ GetClipboardFormatNameA(UINT format, LPSTR lpszFormatName, int cchMaxCount) return 0; } RtlInitUnicodeString(&FormatName, lpBuffer); + FormatName.Length = 0; + FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR); + FormatName.Buffer = lpBuffer; Length = NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount); HEAP_strcpyWtoA(lpszFormatName, lpBuffer, Length); HEAP_free(lpBuffer); @@ -121,7 +124,9 @@ GetClipboardFormatNameW(UINT format, LPWSTR lpszFormatName, INT cchMaxCount) { UNICODE_STRING FormatName; - RtlInitUnicodeString(&FormatName, lpszFormatName); + FormatName.Length = 0; + FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR); + FormatName.Buffer = (PWSTR)lpszFormatName; return NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount); } diff --git a/reactos/subsys/win32k/ntuser/clipboard.c b/reactos/subsys/win32k/ntuser/clipboard.c index 4311b3f14f0..3881ed51a71 100644 --- a/reactos/subsys/win32k/ntuser/clipboard.c +++ b/reactos/subsys/win32k/ntuser/clipboard.c @@ -24,7 +24,14 @@ * PROGRAMER: Filip Navara */ +#include +#include +#include +#include +#include #include +#include +#include #define NDEBUG #include @@ -33,6 +40,13 @@ PW32THREAD ClipboardThread; HWND ClipboardWindow; #endif +INT FASTCALL +IntGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName) +{ + UNIMPLEMENTED; + return 0; +} + UINT FASTCALL IntEnumClipboardFormats(UINT format) { @@ -118,8 +132,70 @@ INT STDCALL NtUserGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName, INT cchMaxCount) { - UNIMPLEMENTED - return 0; + INT Ret; + NTSTATUS Status; + PWSTR Buf; + UNICODE_STRING SafeFormatName, BufFormatName; + + if((cchMaxCount < 1) || !FormatName) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + return 0; + } + + /* copy the FormatName UNICODE_STRING structure */ + Status = MmCopyFromCaller(&SafeFormatName, FormatName, sizeof(UNICODE_STRING)); + if(!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + return 0; + } + + /* Allocate memory for the string */ + Buf = ExAllocatePool(NonPagedPool, cchMaxCount * sizeof(WCHAR)); + if(!Buf) + { + SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + /* Setup internal unicode string */ + BufFormatName.Length = 0; + BufFormatName.MaximumLength = min(cchMaxCount * sizeof(WCHAR), SafeFormatName.MaximumLength); + BufFormatName.Buffer = Buf; + + if(BufFormatName.MaximumLength < sizeof(WCHAR)) + { + ExFreePool(Buf); + SetLastWin32Error(ERROR_INVALID_PARAMETER); + return 0; + } + + Ret = IntGetClipboardFormatName(format, &BufFormatName); + + /* copy the UNICODE_STRING buffer back to the user */ + Status = MmCopyToCaller(SafeFormatName.Buffer, BufFormatName.Buffer, BufFormatName.MaximumLength); + if(!NT_SUCCESS(Status)) + { + ExFreePool(Buf); + SetLastNtError(Status); + return 0; + } + + BufFormatName.MaximumLength = SafeFormatName.MaximumLength; + BufFormatName.Buffer = SafeFormatName.Buffer; + + /* update the UNICODE_STRING structure (only the Length member should change) */ + Status = MmCopyToCaller(FormatName, &BufFormatName, sizeof(UNICODE_STRING)); + if(!NT_SUCCESS(Status)) + { + ExFreePool(Buf); + SetLastNtError(Status); + return 0; + } + + ExFreePool(Buf); + return Ret; } HWND STDCALL