[PATCH v2 07/12] win32u: Introduce data-only mode in NtUserGetClipboardData.

Huw Davies huw at codeweavers.com
Tue Apr 26 10:06:06 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/win32u/clipboard.c | 19 +++++++++++++++----
 include/ntuser.h        |  1 +
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/dlls/win32u/clipboard.c b/dlls/win32u/clipboard.c
index 63306702b1c..67bdd0ba391 100644
--- a/dlls/win32u/clipboard.c
+++ b/dlls/win32u/clipboard.c
@@ -631,7 +631,7 @@ done:
  */
 HANDLE WINAPI NtUserGetClipboardData( UINT format, struct get_clipboard_params *params )
 {
-    struct cached_format *cache;
+    struct cached_format *cache = NULL;
     NTSTATUS status;
     UINT from, data_seqno;
     size_t size;
@@ -642,7 +642,7 @@ HANDLE WINAPI NtUserGetClipboardData( UINT format, struct get_clipboard_params *
     {
         pthread_mutex_lock( &clipboard_mutex );
 
-        cache = get_cached_format( format );
+        if (!params->data_only) cache = get_cached_format( format );
 
         SERVER_START_REQ( get_clipboard_data )
         {
@@ -662,6 +662,8 @@ HANDLE WINAPI NtUserGetClipboardData( UINT format, struct get_clipboard_params *
         }
         SERVER_END_REQ;
 
+        params->size = size;
+
         if (!status && size)
         {
             if (cache)
@@ -679,8 +681,18 @@ HANDLE WINAPI NtUserGetClipboardData( UINT format, struct get_clipboard_params *
                 list_add_tail( &formats_to_free, &cache->entry );
             }
 
+            if (params->data_only)
+            {
+                pthread_mutex_unlock( &clipboard_mutex );
+                return params->data;
+            }
+
             /* allocate new cache entry */
-            if (!(cache = malloc( sizeof(*cache) ))) return 0;
+            if (!(cache = malloc( sizeof(*cache) )))
+            {
+                pthread_mutex_unlock( &clipboard_mutex );
+                return 0;
+            }
 
             cache->format = format;
             cache->seqno  = data_seqno;
@@ -690,7 +702,6 @@ HANDLE WINAPI NtUserGetClipboardData( UINT format, struct get_clipboard_params *
             pthread_mutex_unlock( &clipboard_mutex );
             TRACE( "%s needs unmarshaling\n", debugstr_format( format ) );
             params->data_size = ~0;
-            params->size = size;
             return 0;
         }
         pthread_mutex_unlock( &clipboard_mutex );
diff --git a/include/ntuser.h b/include/ntuser.h
index f49c9bc7723..cad90b91882 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -257,6 +257,7 @@ struct get_clipboard_params
     size_t size;
     size_t data_size;
     UINT   seqno;
+    BOOL data_only;
 };
 
 /* NtUserSetClipboardData params, not compatible with Windows */
-- 
2.25.1




More information about the wine-devel mailing list