You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by pe...@apache.org on 2026/08/29 11:59:17 UTC
(openoffice) 14/17: dtrans: an Any holding a window handle is not a struct to cast
This is an automated email from the ASF dual-hosted git repository.
leginee pushed a commit to branch win10-msvc-trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 63763b62be6e84c055b8942b2b17f00d18f25d29
Author: Peter Kovacs <pe...@apache.org>
AuthorDate: Sat Aug 29 13:53:51 2026 +0200
dtrans: an Any holding a window handle is not a struct to cast
The dnd services take the frame's HWND through their initialize() argument
sequence, and read it out with
m_hWnd = *(HWND*)aArguments[0].getValue();
That does not extract the value; it reinterprets whatever the Any holds at
that address. Window::GetDragSource()/GetDropTarget() put it in as
(sal_uInt32), so on x64 the read takes eight bytes where four were written
and the top half of the handle is whatever the Any's inline storage
happened to be left holding. The handle that reaches RegisterDragDrop is
then not the frame's.
The x86 build only ever worked by coincidence -- a sal_uInt32 Any stores
four bytes at exactly that offset and HWND was four bytes wide. Both
halves of that coincidence end on x64.
So say what is meant: send the handle as sal_uInt64, which holds one on
either architecture, and extract it with >>=. operator>>=( const Any &,
sal_uInt64 & ) accepts UNSIGNED_LONG as well as UNSIGNED_HYPER (cppu's
Any.hxx), so a caller still passing a 32-bit handle keeps working --
dtrans/test/win32/dnd/atlwindow.cxx is one, and is deliberately left alone.
The OS/2 sources read the same two arguments the same way, and change with
them so there is one contract rather than two.
This is not the cause of the reported "cannot drag anything into the
office" on Windows; that is the subsystem version, and has its own commit.
It is a latent x64 defect found while looking for it.
Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWgzQY2r1XwFvgeLPFWPsi
---
main/dtrans/source/os2/dnd/DragSource.cxx | 4 +++-
main/dtrans/source/os2/dnd/DropTarget.cxx | 4 +++-
main/dtrans/source/win32/dnd/source.cxx | 6 +++++-
main/dtrans/source/win32/dnd/target.cxx | 4 +++-
main/vcl/source/window/window.cxx | 4 ++--
5 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/main/dtrans/source/os2/dnd/DragSource.cxx b/main/dtrans/source/os2/dnd/DragSource.cxx
index 7fe92424b6..22f39767ee 100644
--- a/main/dtrans/source/os2/dnd/DragSource.cxx
+++ b/main/dtrans/source/os2/dnd/DragSource.cxx
@@ -72,7 +72,9 @@ void SAL_CALL DragSource::initialize( const Sequence< Any >& aArguments )
static_cast<OWeakObject*>(this));
}
- m_hWnd = *(HWND*)aArguments[1].getValue();
+ sal_uInt64 nWindowHandle = 0;
+ aArguments[1] >>= nWindowHandle;
+ m_hWnd = (HWND)(sal_uIntPtr) nWindowHandle;
debug_printf("DragSource::initialize hwnd %x", m_hWnd);
// init done in DropTarget, window is already subclassed
SetWindowDragSourcePtr( m_hWnd, this);
diff --git a/main/dtrans/source/os2/dnd/DropTarget.cxx b/main/dtrans/source/os2/dnd/DropTarget.cxx
index 0d98987143..f1296c4078 100644
--- a/main/dtrans/source/os2/dnd/DropTarget.cxx
+++ b/main/dtrans/source/os2/dnd/DropTarget.cxx
@@ -73,7 +73,9 @@ void SAL_CALL DropTarget::initialize(const Sequence< Any >& aArguments)
static_cast<OWeakObject*>(this));
}
- m_hWnd = *(HWND*) aArguments[0].getValue();
+ sal_uInt64 nWindowHandle = 0;
+ aArguments[0] >>= nWindowHandle;
+ m_hWnd = (HWND)(sal_uIntPtr) nWindowHandle;
debug_printf("DropTarget::initialize hwnd %x", m_hWnd);
// subclass window to allow intercepting D&D messages
diff --git a/main/dtrans/source/win32/dnd/source.cxx b/main/dtrans/source/win32/dnd/source.cxx
index 21188a1088..2c4ccca52d 100644
--- a/main/dtrans/source/win32/dnd/source.cxx
+++ b/main/dtrans/source/win32/dnd/source.cxx
@@ -162,7 +162,11 @@ void DragSource::StartDragImpl(
void SAL_CALL DragSource::initialize( const Sequence< Any >& aArguments )
{
if( aArguments.getLength() >=2)
- m_hAppWindow= *(HWND*)aArguments[1].getValue();
+ {
+ sal_uInt64 nWindowHandle= 0;
+ aArguments[1] >>= nWindowHandle;
+ m_hAppWindow= (HWND)(sal_uIntPtr) nWindowHandle;
+ }
OSL_ASSERT( IsWindow( m_hAppWindow) );
}
diff --git a/main/dtrans/source/win32/dnd/target.cxx b/main/dtrans/source/win32/dnd/target.cxx
index f688cf53a8..6595b4bf65 100644
--- a/main/dtrans/source/win32/dnd/target.cxx
+++ b/main/dtrans/source/win32/dnd/target.cxx
@@ -134,7 +134,9 @@ void SAL_CALL DropTarget::initialize( const Sequence< Any >& aArguments )
if( aArguments.getLength() > 0)
{
// Get the window handle from aArgument. It is needed for RegisterDragDrop.
- m_hWnd= *(HWND*)aArguments[0].getValue();
+ sal_uInt64 nWindowHandle= 0;
+ aArguments[0] >>= nWindowHandle;
+ m_hWnd= (HWND)(sal_uIntPtr) nWindowHandle;
OSL_ASSERT( IsWindow( m_hWnd) );
// Obtain the id of the thread that created the window
diff --git a/main/vcl/source/window/window.cxx b/main/vcl/source/window/window.cxx
index 3daef8b1dd..2bd4f73f2a 100644
--- a/main/vcl/source/window/window.cxx
+++ b/main/vcl/source/window/window.cxx
@@ -8614,8 +8614,8 @@ uno::Reference< XDragSource > Window::GetDragSource()
#if defined WNT || defined OS2
aDragSourceSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDragSource" );
aDropTargetSN = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.OleDropTarget" );
- aDragSourceAL[ 1 ] = makeAny( (sal_uInt32) pEnvData->hWnd );
- aDropTargetAL[ 0 ] = makeAny( (sal_uInt32) pEnvData->hWnd );
+ aDragSourceAL[ 1 ] = makeAny( (sal_uInt64)(sal_uIntPtr) pEnvData->hWnd );
+ aDropTargetAL[ 0 ] = makeAny( (sal_uInt64)(sal_uIntPtr) pEnvData->hWnd );
#elif defined QUARTZ
/* FIXME: Mac OS X specific dnd interface does not exist! *
* Using Windows based dnd as a temporary solution */