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

  • SEARCH
  • Home
  • 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 7929213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:00:21+00:00 2026-06-03T20:00:21+00:00

I am attempting to register for notifications on USB device arrival and device remove

  • 0

I am attempting to register for notifications on USB device arrival and device remove complete events from a java swing application.

I have successfully called

SetWindowLong(hWnd, MyUser32.GWLP_WNDPROC, listener);

to register a listener and I am getting notifications of type WM_DEVICECHANGE. So far so good.

Now I want to call RegisterDeviceNotification to ensure that I am notified of device arrival and remove complete events. Here is what I have tried:

HWND hWnd = new HWND();
hWnd.setPointer(Native.getWindowPointer(frame));
DEV_BROADCAST_DEVICEINTERFACE filter = new DEV_BROADCAST_DEVICEINTERFACE();
filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;       
filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
filter.dbcc_name = new char[1];
filter.dbcc_reserved = new DWORD(0);
filter.dbcc_size = new DWORD(filter.size());
filter.dbcc_size = new DWORD(filter.size());

long retVal = MyUser32.MYINSTANCE.RegisterDeviceNotification(new HANDLE(hWnd.getPointer()), filter.getPointer(), DEVICE_NOTIFY_WINDOW_HANDLE);

if (retVal != 0) {
    System.out.println("Error registering for usb: " + Native.getLastError());
}

My JNA declarations are:

public long RegisterDeviceNotification(HANDLE hRecipient, Pointer NotificationFilter, DWORD Flags);

public static class DEV_BROADCAST_DEVICEINTERFACE extends Structure {
      public DWORD dbcc_size;
      public DWORD dbcc_devicetype;
      public DWORD dbcc_reserved;
      public GUID  dbcc_classguid;
      public char[] dbcc_name;
}

public static final GUID GUID_DEVINTERFACE_USB_DEVICE = new GUID(new byte[] {
        (byte)0xA5, (byte)0xDC, (byte)0xBF, 0x10, 0x65, 0x30, 0x11, (byte)0xD2, (byte)0x90, 0x1F, 0x00, (byte)0xC0, 0x4F, (byte)0xB9, 0x51, (byte)0xED          
});

I am always receiving an error 1066. Any help would be appreciated. If more information is required let me know and I can include it.

  • 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-03T20:00:22+00:00Added an answer on June 3, 2026 at 8:00 pm

    Declaring RegisterDeviceNotification to return long was causing the problem. According to the JNA FAQ, JNA FAQ

    Actually, no one ever asks this question, but they really need the
    answer. Do not use Java long!

    On Windows, you can use a Java int, since the native long type is
    always 32 bits. On any other platform, the type may be 32 or 64 bits,
    so you should use the NativeLong type to ensure the proper size is
    used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am attempting to add push notifications to an application that I have created. I
We are attempting to port a legacy application from an old monolithic RTOS to
I'm (attempting) to use push notifications with Android via Urban Airship. I've register for
I am attempting to register the following function from Irrlicht, dimension2df: template <class U>
I am attempting to register my device with C2DM and am having major issues.
I am attempting to register a .dll using RegAsm. It is a .NET 2.0
Attempting to use the data series from this example no longer passes the JSONLint
Attempting/struggling to get registration and sign-up working within an active admin project. I have
Attempting to change the files folder location in a Drupal site from /files to
Attempting a beginner's tutorial. I have the following in my head: <script type=text/javascript charset=utf-8

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.