]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix drag-n-drop on MS-Windows
authorCecilio Pardo <cpardo@imayhem.com>
Thu, 14 Nov 2024 08:55:56 +0000 (09:55 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 20 Nov 2024 16:11:27 +0000 (17:11 +0100)
* src/w32fns.c (struct w32_drop_target): New member 'ref_count'.
(w32_drop_target_AddRef): Increment reference count.
(w32_drop_target_Release): Decrement reference count, and free the
target only if the reference count is zero.
(w32_createwindow): Initialize reference count.  (Bug#74312)

(cherry picked from commit b83a45eab53b8e6d8f3be45c0acb9a42a5262cb0)

src/w32fns.c

index 1bd3d5099e2b5cfdc0569a88c447411227da389b..e2455b9271eba27b57e9af1ca70b8b662afc42a8 100644 (file)
@@ -2562,6 +2562,7 @@ struct w32_drop_target {
   /* i_drop_target must be the first member.  */
   IDropTarget i_drop_target;
   HWND hwnd;
+  int ref_count;
 };
 
 static HRESULT STDMETHODCALLTYPE
@@ -2573,13 +2574,16 @@ w32_drop_target_QueryInterface (IDropTarget *t, REFIID ri, void **r)
 static ULONG STDMETHODCALLTYPE
 w32_drop_target_AddRef (IDropTarget *This)
 {
-  return 1;
+  struct w32_drop_target *target = (struct w32_drop_target *) This;
+  return ++target->ref_count;
 }
 
 static ULONG STDMETHODCALLTYPE
 w32_drop_target_Release (IDropTarget *This)
 {
   struct w32_drop_target *target = (struct w32_drop_target *) This;
+  if (--target->ref_count > 0)
+    return target->ref_count;
   free (target->i_drop_target.lpVtbl);
   free (target);
   return 0;
@@ -2770,6 +2774,7 @@ w32_createwindow (struct frame *f, int *coords)
          if (vtbl != NULL)
            {
              drop_target->hwnd = hwnd;
+             drop_target->ref_count = 0;
              drop_target->i_drop_target.lpVtbl = vtbl;
              vtbl->QueryInterface = w32_drop_target_QueryInterface;
              vtbl->AddRef = w32_drop_target_AddRef;