Mapping Windows API to Java - JNA

I am trying to use JNA to implement the functions in the Win32 USB API (http://www2.hawaii.edu/~hermany/api.htm)
I am trying to figure out how to map the following "HDEVINFO" which is defined as "typedef PVOID", which in turn is defined as typedef void* PVOID; (http://msdn2.microsoft.com/en-us/library/bb401729.aspx)
===================================================================================
     * From the API provided by Microsoft (http://msdn2.microsoft.com/en-us/library/ms792959.aspx)
     * HDEVINFO
     * SetupDiGetClassDevs(
     * IN LPGUID ClassGuid, OPTIONAL
     * IN PCTSTR Enumerator, OPTIONAL
     * IN HWND hwndParent, OPTIONAL
     * IN DWORD Flags
http://www.alanmacek.com/usb/DDKFiles/setupapi.h
typedef PVOID HDEVINFO;
====================================================================================
HDEVINFO is supposed to be an array of structures for the device information set. How do I map HDEVINFO on to the Java class that mirrors the SetupDiGetClassDevs function in the API?

Well I am using JNA (jna.jar) to make the call to the function available in the setupapi.dll. In the following code: Setupapi INSTANCE = (Setupapi) Native.loadLibrary("setupapi", Setupapi.class);*, this is what is being done. I am new to using JNA. Also, It would be great to have a resource that lists all the available functions for a Windows DLL. MSDN, of course is a good resource but it does not provide search results for a dll. One has to know the function to be called.
public interface Setupapi extends StdCallLibrary {
      * Allocating an instance of the native library using the Native.loadLibrary(Class) method,
      * providing the native library interface
      * This instance is for convenient reuse. Alternatively, we can load the library into a
      * local variable so that it will be available for garbage collection when it goes out of scope
     Setupapi INSTANCE = (Setupapi) Native.loadLibrary("setupapi", Setupapi.class);
      * Declaring native structures to pass to  native functions.
      * To do this, create a class that extends Structure (https://jna.dev.java.net/javadoc/com/sun/jna/Structure.html)
      * and add public fields
      * (which may include arrays or nested structures).
      * Declaring methods that mirror the functions in the target library by defining Java methods with
      * the same name and argument types as the native function
      * (refer to the basic mappings (https://jna.dev.java.net/#mapping) or the
      * detailed table of type mappings (https://jna.dev.java.net/javadoc/overview-summary.html#marshalling) ).
      * From the API provided by Microsoft (http://msdn2.microsoft.com/en-us/library/ms792959.aspx)
      * HDEVINFO
      * SetupDiGetClassDevs(
      * IN LPGUID  ClassGuid,  OPTIONAL
      * IN PCTSTR  Enumerator,  OPTIONAL
      * IN HWND  hwndParent,  OPTIONAL
      * IN DWORD  Flags
      // TODO: public HDEVINFO SetupDiGetClassDevs(
}

Similar Messages

  • Using Windows API in Java

    hi,
    How can i use windows api in java.
    regards
    Malik Faisal

    By writing a wrapper in JNI.
    JNI Tutorial.

  • How do i invoke Windows APIs in JAVA??? Please help.

    Is there a way to invoke Windows APIs in Java??? Please help......Thankx

    Short answer, you don't. However, you should look at Java Native Interface (JNI) very closely. It will allow you to wrap the Win32 API calls so that Java can call your wrapper methods. Another side to it, although not necessarily related to your question is a JavaBeans to COM bridge that you may want to look into as well, though it's probably not going to be a solution for what you're wanting to do right now.

  • Can I call Windows API in java?

    How can I?

    you can use JNI. I do not know much about it, but there are also some tools that make it simplier to you. One of the most famous is one call JIntegra.You pass to it a dll and it will generate for you the Java classes needed to access the API.

  • Mapped windows drive -  Java performance problem

    I have a mapped windows drive to which I am writing files sized from few kbs to GBs, Now I am facing performance problem.
    Time for writing to local drive file with 4 MB - 1.6 seconds.
    Time for writing to mapped drive : 31 seconds.
    Please give me the ways to improve the mapped drive file access.
    Note I am using buffered streams and all , I am primarly expecting some thing from windows side.
    Renjith.

    I am copying the file from local drive to a mapped drive.
    ovxFileName = filename.substring(attachmentsFolder.length() + 1);
                   BufferedInputStream reader = new BufferedInputStream(
                             new FileInputStream(filename));
                   BufferedOutputStream writer = new BufferedOutputStream(
                             new FileOutputStream(commonLocationForOVX + File.separator
                                       + ovxFileName));
                   String str = "";
                   TimerUtility timer = new TimerUtility();
                   timer.startTimer();
                   int val = 0;
                   while ((val = reader.read()) != -1) {
                        writer.write(val);
                   writer.close();
                   reader.close();
                   timer.stopTimer();

  • Creating a New Folder in Windows Registry by java coding

    Good morning,
    hi to all,
    how can I create a New folder in Window Registry using Java coding. Can anybody help me out pls.
    I begin waiting for ur reply.
    Thanx

    Why do you feel you need to write to the Windows registry directly? Take a look at the Preferences class.
    {color:#0000ff}http://java.sun.com/javase/6/docs/api/java/util/prefs/Preferences.html{color}
    luck, db

  • New "Windows Programming Using Java" Website

    Our newly created "Windows Programming Using Java" website (http://fivedots.coe.psu.ac.th/~ad/winJava/) is for programmers who want to extend Java's capabilities on Windows XP and/or Vista, but aren't sure where to start. One of the drawbacks of Java's portability is that many Java programmers have a rather sketchy knowledge of Windows-specific programming.
    We plan to explain how Java applications can utilize Windows application software, OS features, and hardware beyond the reach of Java's standard libraries. A variety of Java/Windows programming techniques will be explained, including:
    * Java's employment of the Win32 API via C, JNI, and J/Invoke.
    * Java's utilization of Window's Command Line Interface (CLI) and batch files, accessed through Java's Runtime, ProcessBuilder, and Process classes.
    * Java and Windows object-based scripting, centered around the use of VBScript, Windows Script Host (WSH), and Windows Management Instrumentation (WMI).
    * Java interoperability with COM, including hosting of ActiveX controls in Swing containers using jacoZoom.
    This website is a work in progress, with four chapters available for download at the moment. We'll be adding more regularly, and would love feedback on what we're doing.
    Thanks,
    Gayathri Singh and Andrew Davison
    [email protected] and [email protected]
    Edited by: AndrewDavison on Jun 20, 2008 1:36 AM

    Hi, I am looking the similar kind of requirement that you had done.. Do you have any more details on the code that is working for you . All i need is if the user logs in successfully in windows, the the app should be accessible. Please let me know if you have the code with you on this problem.
    Thanks in advance
    "what i meant is the we b applications running in my system, when i access the application iam able to to login automatically with windows authentication and now in case of other users following process happened:"

  • Windows Programming with Java??? Is it possible???

    I have a small request from a client (Windows User) who wants a really simple POP3 email checker. I basically need to achieve the same thing that many email clients do, where they show some sort of symbol in the System tray when there is new email. I, however want to do this without the actual email client. All I want is the checker. This program will not download the email, gather information or anything. It will simply check the POP3 account and let the user know if there is new email.
    1.Can I get an icon to appear in the system tray and have a program that runs in the background, simply checking the POP3 account for new mail???
    2.If it is possible to interact with windows, then how is it done??? If this is too large of a question and you know of some resources that can answer this question for me, that will do.
    3.Is it even possible to have Java programs run in the background without appearing in the task bar??
    4. Am I trying to do something with Java that it just plain cannot do???

    Another really god option is to use the coroutine package from http://www.nevaobject.com/java/index.htm. This allows you invoke COM and Windows API's without having to write the JNI yourself. Its about $695 for a site-wide development license and has no binary distribution costs. A nice, cheap solution to spending lots of hours doing it youself. From the few things I tinkered with, it really does a great job too, but I have not deployed in a real production environment.
    Chuck

  • JAXB as standard API for Java Mappings in XI?

    Hi there,
    Has anyone on this forum implemented Java mappings in XI using JAXB (reference implementation for XML/JAVA data bindings of SUN)?
    If Yes, can you please share any experiences?
    We're considering to use this API for Java Mappings in XI but first would like to get more background info.
    Cheers,
    Rob.

    Hi Roberto,
    Have tried implementing Java mapping using JAXB technique couple of years ago. However I was not able to test the mapping in XI/PI environment.
    <ul>
    <li>There is no in built support for JAXB from SAP XI.</li>
    <li>There is no documentation available from SAP on JAXB hence it is difficult to implement the mapping.</li>
    <li>We have to import JAXB specific jars along with the mapping code. my attempt to execute the mapping test in IR tool was unsuccessful It was running fine in standalone mode in local PC </li>
    </ul>
    [My question on SDN on same topic..|Java Mapping Using JAXB [Java Arch for XML Binding];
    Thanks and regards,
    Ananth

  • Window programming using java

    hi,
    can anybody suggest me how to go with widow API using java?
    say like if i want to shutdown my computer after pressing the button.
    thanks in advance,
    sachin

    Given the platform-independant nature of Java, I'm not sure there's a way to program Windows directly using it. Certainly there's no Java methods for this.
    However, it is possible to wrap windows dlls and access them from java, and this is probably the route you'll have to take. It's not particularly easy, but it's effective.
    I remember there being an article on gamelan.com about this, sorry don't have the link anymore - you'll have to search.

  • Install. CSR with  cmd keytool or windows API.

    hello,
    I've done this command * but the certificate doesn't appear in Windows XP (self-service kiosk) controlPanel/Java/Security/certificate...import.
    * C:\Program Files\Java\jre1.6.0_07\bin>keytool.exe -import -alias taratata -file "C:\tmp\taratata.csr" -trustcacerts -v
    I could do effectively with windows API but i need to automate the install from the command line.
    any suggestion will be appreciate.
    regards

    yes, the command created .keystore file, but how to specify a command known by the java control panel?
    or how to make known the keystore to the java control panel?

  • Calling a COM API from Java

    Hi,
    is it possible to call methods on a COM API that is written in VB on a windows machine from Java? I'd rather not have to take the route of using JNI and keep this 100% Java. Ideally, I'm looking for a Java solution that would allow me to call methods in the COM API from different platforms (Win / Linux / Mac).
    Thanks,
    Shane

    I've used Jacob. You can get it at:
    http://danadler.com/jacob/
    Don't understand your Linux/Mac angle though. I've heard COM was ported to other platforms but haven't heard of it being used. Jacob is Win 32 only.
    Dom.

  • Windows User Permissions, JAVA and JNI

    I am a writing a Java program that needs to know if a logged in user on Windows has administrator right or all-permissions. What is the best way to do this?
    I have been looking into JNI but have never used it before. I also am not sure what Windows API calls I would need to make.
    Someone out there has had to have done the same thing. Any help would be much appreciated.
    P.S. I have googled and googled and have yet to find a solution to this problem.
    Thank in advance!
    Kyle

    kyle.bober wrote:
    I am a writing a Java program that needs to know if a logged in user on Windows has administrator right or all-permissions. What is the best way to do this?
    I have been looking into JNI but have never used it before. I also am not sure what Windows API calls I would need to make.
    Someone out there has had to have done the same thing. Any help would be much appreciated.
    P.S. I have googled and googled and have yet to find a solution to this problem.
    Thank in advance!
    KyleOn the Windows side, Google for "check if administrator". One of the top entries is from a MSDN forum.
    If you write or find a Windows command line utility to answer the question, you can invoke it
    in Java with Runtime.exec(), which is a lot easier that JNI.

  • Bing Maps REST route service - java classes

    I am able to use the WSDL to generate the classes required to hit the SOAP Web Service.  But it appears that the classes generated using the SOAP service do not match the classes used for the REST service.  How
    can I generate the Java classes required for hitting the REST Route Web Service.  I am able to call the REST service and get an XML or JSON response, but having issues creating the objects with the data returned.

    The REST and SOAP services are completely different. The SOAP services were created about 8 years ago and the REST services about 4 years ago. The REST services have a bunch more features and functionalities. There are a couple of ways you can consume the
    Bing Maps REST services in Java. The first is to manually parse the responses. Here are some examples:
    http://javaprogramming.language-tutorial.com/2012/10/geocoding-using-bing-rest-api.html
    http://javaprogramming.language-tutorial.com/2012/10/reverse-geocoding-using-bing-rest-api.html
    https://ngjon.wordpress.com/2011/05/20/bing-maps-geocoding-rest-service-java-ized/
    Alternatively you can create a set of classes that can be used for serializing the responses. I have a set of .NET data contracts for the RST services that can be ported to Java here:
    http://msdn.microsoft.com/en-us/library/jj870778.aspx
    I also created some tools to parse the REST responses in an Android app a while back. You can find the code for that here:
    http://bingmapsandroidsdk.codeplex.com/SourceControl/latest#BingMapsAndroidSDK/src/org/bingmaps/rest/BingMapsRestService.java
    http://rbrundritt.wordpress.com

  • Linking two programs via Windows API

    I am writing a program to enhance the usability of an already written program. Someone suggested that I interface the two via the windows API: The program I would like to add functionality to was not written in java and I do not have access to the source code. What was suggested to me was that I track down the handles for the buttons on the program (the buttons being the only important features I need access to) and connect that way.
    This seemed like a good idea....except I have no idea what this guy was talking about! Can someone explain this to me or at least point me in the right direction?
    Thank you very much,
    Plastech

    So how would I find out how to access the buttons
    found in the other application? What is all this
    talk of handles? I am really not very familiar with
    the windows api.Neither am I. After all, this is a Java board.
    And how is it possible that I could access those
    handles from a different program?The "different program" needs to allow you to access them, of course, by offering the appropriate interface.

Maybe you are looking for