

![]() | 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: |
4 messages in net.java.dev.jna.usersRe: [jna-users] Pointer to a caller-a...| From | Sent On | Attachments |
|---|---|---|
| Dave Kennedy | Nov 7, 2008 12:48 pm | .java |
| Timothy Wall | Nov 7, 2008 1:08 pm | |
| Dave Kennedy | Nov 7, 2008 1:31 pm | .java, .java, .java |
| Timothy Wall | Nov 7, 2008 1:45 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] Pointer to a caller-allocated GUID buffer | Actions... |
|---|---|---|
| From: | Dave Kennedy (dave...@gmail.com) | |
| Date: | Nov 7, 2008 1:31:52 pm | |
| List: | net.java.dev.jna.users | |
| Attachments: | ||
Hi,
I have an Exception in thread I'm not sure if SetupDiGetClassDevs is declared correctly Please see attached. Thanks for the response.
run: Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'SetupDiGetClassDevs': The specified procedure could not be found.
at com.sun.jna.Function.<init>(Function.java:129) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:250) at com.sun.jna.Library$Handler.invoke(Library.java:191) at $Proxy1.SetupDiGetClassDevs(Unknown Source) at jna.HID.<init>(HID.java:26) at jna.HID.main(HID.java:32) Java Result: 1 BUILD SUCCESSFUL (total time: 1 second)
On Fri, Nov 7, 2008 at 1:08 PM, Timothy Wall <twal...@dev.java.net> wrote:
I think your Java struct definition is incorrect:
// C code typedef struct _GUID { ULONG Data1; USHORT Data2; USHORT Data3; UCHAR Data4[8]; } GUID
typedef GUID *LPGUID;
ULONG = Java integer USHORT = Java short UCHAR = Java byte
You can inline-initialize the byte[] field to avoid needing an explicit ctor (your ctor was allocating memory incorrectly anyway). Note that the resulting size is supposed to be 16 bytes.
// Correct Java code public static class GUID extends Structure { public int data1; public short data2; public short data3; public byte[] data4 = new byte[8];
}
On Nov 7, 2008, at 3:48 PM, Dave Kennedy wrote:
Hi,
I need to call HidD_GetHidGuid as defined below. How is LPGUID HidGuid defined in JNA? Is the code in the attached file correct? Thanks, Dave
The HidD_GetHidGuid routine returns the device interface GUID for HIDClass devices. http://msdn.microsoft.com/en-us/library/ms790927.aspx
VOID HidD_GetHidGuid( OUT LPGUID HidGuid );
Parameters HidGuid Pointer to a caller-allocated GUID buffer that the routine uses to return the device interface GUID for HIDClass devices.
GUID Globally unique identifier. A 16-byte quantity that is unique, having been generated from the unique identifier on a network card, the current date and time, and a sequence number. This combination of variables is used to allow any party to create identifiers that will be guaranteed not to match another GUID. For more information see the topic, Using GUIDs in Drivers.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package win32;
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; import com.sun.jna.Pointer; import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.IntByReference;
public interface Setupapi extends W32API, HIDLibrary {
//
// Flags controlling what is included in the device information set built
// by SetupDiGetClassDevs
//
public static int DIGCF_DEFAULT = 0x00000001; // only valid with
DIGCF_DEVICEINTERFACE
public static int DIGCF_PRESENT = 0x00000002;
public static int DIGCF_ALLCLASSES =0x00000004;
public static int DIGCF_PROFILE = 0x00000008;
public static int DIGCF_DEVICEINTERFACE = 0x00000010;
Setupapi INSTANCE = (Setupapi) Native.loadLibrary((Platform.isWindows() ? "setupapi" : "c"), Setupapi.class); // http://msdn.microsoft.com/en-us/library/ms792959.aspx // Return a device information set containing // all of the devices in a specified class. // Build a list of all HID devices that are present in the system. // HDEVINFO // SetupDiGetClassDevs( // IN LPGUID ClassGuid, OPTIONAL // IN PCTSTR Enumerator, OPTIONAL // IN HWND hwndParent, OPTIONAL // IN DWORD Flags // ); HANDLEByReference SetupDiGetClassDevs( GUID pClassGuid, PointerByReference pEnumerator, HANDLEByReference hwndParent, // HWND int flags); // DWORD }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package win32;
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Structure; import com.sun.jna.Platform; import com.sun.jna.ptr.PointerByReference;
public interface HIDLibrary extends W32API {
// GUID data type // Type GUID // Data1 As Long // Data2 As Integer // Data3 As Integer // Data4(7) As Byte // End Type public static class GUID extends Structure { public int data1; public short data2; public short data3; public byte[] date4 = new byte[8]; }
HIDLibrary INSTANCE = (HIDLibrary) Native.loadLibrary((Platform.isWindows() ? "hid" : "c"), HIDLibrary.class);
// Obtain the GUID for the HID class void HidD_GetHidGuid(GUID hidGuid); // Retrieves the HID's Vendor ID, Product ID, and Version Number. boolean HidD_GetAttributes(HANDLEByReference HidDeviceObject, PointerByReference Attributes); }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package jna;
/** * * @author Dave */ import com.sun.jna.ptr.PointerByReference; import win32.*;
/** */ public class HID {
public HID () { HIDLibrary hid = HIDLibrary.INSTANCE; HIDLibrary.GUID pClassGuid = new HIDLibrary.GUID(); hid.HidD_GetHidGuid(pClassGuid);
Setupapi setup = Setupapi.INSTANCE;
int flags = setup.DIGCF_ALLCLASSES | setup.DIGCF_PRESENT;
W32API.HANDLEByReference handle = setup.SetupDiGetClassDevs(
pClassGuid, (PointerByReference)null,
(W32API.HANDLEByReference)null, flags);
}
public static void main(String[] args) {
HID hid = new HID ();
} }








.java