

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in net.java.dev.jna.usersRe: [jna-users] Windows device notifi...| From | Sent On | Attachments |
|---|---|---|
| Jim Burke | Mar 20, 2009 9:08 am | |
| Timothy Wall | Mar 20, 2009 9:29 am | |
| Jim Burke | Mar 20, 2009 12:55 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Windows device notification structures | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Mar 20, 2009 9:29:45 am | |
| List: | net.java.dev.jna.users | |
On Mar 20, 2009, at 12:09 PM, Jim Burke wrote:
[Disclaimer: I'm new to both JNA and Windows programming, and although I've searched and read a lot, I still feel pretty clueless]
I'm using JNA to detect USB device addition/removal from a Java app. I'm able to register for the specific device notifications I need and I'm receiving the messages, processing them and forwarding them to the app window just fine. My problem is that I'm struggling with getting at the information from the notification message. The callback function (http://msdn.microsoft.com/en-us/library/ms633573.aspx) looks like this:
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // WM_DEVICECHANGE WPARAM wParam, // device-change event LPARAM lParam // event-specific data );
For the DBT_DEVICEARRIVAL event (http://msdn.microsoft.com/en-us/library/aa363205(VS.85).aspx), the lParam parameter above is:
"A pointer to a structure identifying the device inserted. The structure consists of an event-independent header, followed by event-dependent members that describe the device. To use this structure, treat the structure as a DEV_BROADCAST_HDR structure, then check its dbch_devicetype member to determine the device type."
DEV_BROADCAST_HDR (http://msdn.microsoft.com/en-us/library/aa363246(VS.85).aspx) looks like this:
typedef struct _DEV_BROADCAST_HDR { DWORD dbch_size; DWORD dbch_devicetype; DWORD dbch_reserved; } DEV_BROADCAST_HDR, *PDEV_BROADCAST_HDR;
How do I "treat the structure as a DEV_BROADCAST_HDR" using JNA? Any guidance would be much appreciated.
Create one, then assign its pointer to your LPARAM pointer using STructure.useMemory (or use a ctor for the structure that takes a pointer), e.g.
public MyStructure(Pointer base) { useMemory(base); read(); }
If the memory actually maps to a different type of structure, you can create an instance of the new structure in the same manner (or, if you have several, collect them into a union).
If the LPARAM is effectively *always* a pointer to a DEV_BROADCAST_HDR, then you can safely change the type of the callback parameter from LPARAM to the structure type.







