Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:15:12+00:00 2026-06-14T07:15:12+00:00

I am trying to support drag and drop from a native Windows application into

  • 0

I am trying to support drag and drop from a native Windows application into a Java application. My problem has been that I have no documentation, and so I have been reverse-engineering it. My first issue was that I didn’t know the name of the clipboard format. Working in the debugger, I was able to find the identifier of the custom clipboard format that the application had registered using the system call RegisterClipboardFormat(). And in sun.awt.windows.WDataTransferer, there’s a native interface to the system call GetClipboardFormatName(), by which I managed to extract the registered name. (For reference, though it doesn’t bear directly on the problem, the application is Eudora 7.1 and the name is EudoraTransferClipboardFormat.)

Now I anticipate needing to do this again, and I’d rather write a small utility now because I’m certain to forget the internal data structures of the library by the time I need it later. The problem is that the relevant clipboard format identifier is buried inside a subclass instance of SunDropTargetContextPeer as private member currentT. Navigation from the drag-and-drop event to this object likewise goes through a protected member. And the system call interface is likewise declared private. This is all visible in the debugger, but not in ordinary code.

My goal is to extract the value of currentT (since that’s what the drag and drop subsystem actually sees) and display the name of the registered clipboard formats therein. I suspect various abuses of the class loader and security system are necessary to get this working as a publishable utility written in Java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:15:13+00:00Added an answer on June 14, 2026 at 7:15 am

    I solved this problem by using Java reflection calls to obtain the relevant internal members. The key part of this is the function setAccessible on the Field objects. This function turns off access control on the Field object, allowing public access, albeit not through the ordinary syntax. (Note the actual function name; it’s not subvertAccessControls.) This call succeeds in the ordinary JRE environment and probably won’t work in, say, an applet. I didn’t bother checking this because this is for a developer tool to examine a drag event for native types that won’t otherwise show up because (1) the application doesn’t know about the native type and (2) there’s no data flavor to translate the native data transfer into a Java object. Therefore, I only need it running once per application that has a drag type I’m reverse engineering; running in the ordinary JRE is all I need.

    Thank goodness I didn’t have to break out java.lang.instrument or even JVMTI. I did, however, have to abuse the security system.

    Tested code fragment below. The variable long native_types[] is the output. DropTargetDragEvent dtde is the input; it’s an argument to an event handler.

    long native_types[];
    try {
        /*
         * Retrieve the drop target context.
         *
         * We can retrieve this member directly, because it's a public field.
         */
        DropTargetContext dtc = ( ( DropTarget ) dtde.getSource() ).getDropTargetContext();
        /*
         * Retrieve the drop target context peer.
         *
         * We cannot retrieve this member without reflection, because it's a private field. We get the class
         * object from the public class declaration. The field "dropTargetContextPeer" is private, so we
         * have to retrieve with a reflection call and then set it to be accessible so that we don't get
         * IllegalAccessException when we call get() on the field. Since we're only going to use reflection
         * on the drop target context peer, we don't bother trying to cast it and just leave it declared
         * as Object.
         */
        Class<DropTargetContext> DTC_class = DropTargetContext.class;
        Field DTCP_field = DTC_class.getDeclaredField( "dropTargetContextPeer" );
        DTCP_field.setAccessible( true );
        Object dtcp = DTCP_field.get( dtc );
        /*
         * Retrieve the array of native types.
         *
         * This is almost exactly analogous to the previous retrieval, but with the exception that the field
         * is defined in the superclass, not the class itself. Because the field is declared private, we can't
         * simply use getField(), since that only works on public fields. So we get the class object for the
         * parent class and proceed as before.
         *
         * As a bonus, this routine is cross-platform. The class sun.awt.windows.WDropTargetContextPeer is
         * the implementation class for sun.awt.dnd.SunDropTargetContextPeer for Windows. The type identifiers,
         * though, all fit into a long for every platform.
         */
        Class<?> DTCP_class = dtcp.getClass();
        Class<?> DTCP_superclass = DTCP_class.getSuperclass();
        Field CT_field = DTCP_superclass.getDeclaredField( "currentT" );
        CT_field.setAccessible( true );
        native_types = ( long[] ) CT_field.get( dtcp );
    } catch ( Exception e ) {
        throw new RuntimeException( "Did not retrieve native types.", e );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java web service I am trying to support java isn't really
I started trying to implement drag-and-drop of virtual files (from a C# 4/WPF app)
I'm trying to detect the HTML5 Drag And Drop support in JavaScript. Modernizr seems
I have an application with a file and folder list control which supports Drag&Drop
I am trying to trap drag and drop events from the standard Apple address
I'm trying to support landscape mode in my gl iOS application. I have a
I am trying to support CORS in my Node.js application that uses the Express.js
I'm trying allow drag and drop to the tray icon on my application. I
I have the following regular expression: ^[-+]?[\d{0,3},?\d{3}]*\.?\d+$ I am trying to support numbers of
I am trying to set support information on machines with C#. I have one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.