Why "DLLs with JNative" demo "Cannot find class or type named org.xvolks.jnative.util.ANT_DLL"?

edited March 2014 in Questions about Code

Dear All,

I am trying to implement DLL calls in my code and am starting with the tutorial on the wiki. I copied and pasted the code from the wiki, and include it here:

DLL_test_1.pde

import org.xvolks.test.bug.*;
// ... the other imports ...
import org.xvolks.jnative.com.*;

void setup()
{
  JNative.setLoggingEnabled(true); // show what JNative is doing!
  try
  {
    int blah=org.xvolks.jnative.util.ANT_DLL.ANT_Init((byte)0,(short)57600); // Call the first native function. This initializes the USB radio via the manufacturer's DLL. >>>>>THIS IS THE LINE THAT FAILS<<<<<
    print(blah); // should return '1' upon success. This was easy so far!
  }
  catch (NativeException e) // traps in case anything naughty happens
  {
  e.printStackTrace();
  }
  catch (IllegalAccessException e)
  {
    e.printStackTrace();
  }
}


void draw()
{
 exit(); // I put this in to kill the program after compiling
}

ANT_DLL.java

package org.xvolks.jnative.util;

import processing.core.*;

import org.xvolks.test.bug.*;
// ... the other imports ...
import org.xvolks.jnative.com.*;

public class ANT_DLL extends PApplet
{
  public static final String DLL_NAME = "ANT_DLL.DLL";

  //Cache the JNative object between calls.
  private static JNative nANT_Init;  // Native-side function names
  private static JNative nANT_AssignResponseFunction; //one for each DLL function you will use...

  // The actual DLL export, most likely from API documentation / header file:
  // __declspec(dllexport) BOOL ANT_Init(UCHAR ucUSBDeviceNum, USHORT usBaudrate);

  // Java-side function name
  public static int ANT_Init(byte ucUSBDeviceNum, short usBaudrate) throws NativeException, IllegalAccessException 
  {
    if(nANT_Init == null) 
    {
      nANT_Init = new JNative(DLL_NAME, "_ANT_Init");  // The actual "decorated" name in the DLL
      //BOOL is in fact an INT
      nANT_Init.setRetVal(Type.INT);  // tell JNative's DLL what kind of return data to expect
    }

    nANT_Init.setParameter(0, ucUSBDeviceNum); // tell JNative's DLL what data to pass to the native function, in what order.
    nANT_Init.setParameter(1, usBaudrate);    // ...
    nANT_Init.invoke();  // Finally, execute the native function

    return nANT_Init.getRetValAsInt(); // get native call's return value
  }
}

When I compile, I get:

Cannot find class or type named "org.xvolks.jnative.util.ANT_DLL"

I know that this code should not fully run on my machine, as I have nothing called "ANT_DLL.DLL", but I would expect it to fail at a different point, preferably inside the .java file. I have tried running as Administrator, but that doesn't change anything.

I am running Processing 2.1.1 on Windows 7 64-bit.

What am I missing here? Where should this fail if the code compiled properly, but was missing the proper DLL? Is this a Processing 2.x vs 1.x issue?

Thanks for your help!

Tagged:

Answers

  • I closed out processing, re-opened the sketch, only to find the .java file was gone (!). I copied and pasted the above text back into ANT_DLL.java and now I get:

    Problem moving ANT_DLL.java to the build folder
    java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    
  • Processing doesn't handle packages, not even in .java files. You should compile with the real Java compiler.

    Note that your ANT_DLL.java file should reside in a org/xvolks/jnative/util folder.

    Or drop the package definition, if that's only for your own usage.

Sign In or Register to comment.