解决方案 »

  1.   

    我自己找到方法了import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Structure;public class MyTest {
    public interface MyApi extends Library
    {
                   public static class EVENT extends Structure{
                               public int id;
                               public ByteByReference pvBuffer;       //定义一个byte数组存放数据    
             }
            MyApi   INSTANCE   =   (MyApi)Native.loadLibrary("MyTest", MyApi.class);   //加载C中的动态库MyTest.dll
            public   int   WaitForEvent(EVENT pEvent);   //WaitForEvent是MyTest.dll 提供的接口函数,作用是使用pEvent来接收获取到的事件
    public static void main(String [] args)
            {
                    EVENTpEvent=new EVENT();
                    pEvent.i=0;
                    pEvent.pvBuffer = new ByteByReference();
    Memory mymem = new Memory(300);//300个c字符
    mymem.setString(0, "");
    pEvent.pvBuffer.setPointer(mymem);
                    WaitForEvent( pEvent);     //WaitForEvent会改变pEvent的内容
                    System.out.println(Integer.toString(pEvent.id));  //输出结果:id的值被改变,不再是0
                    System.out.println(pEvent.pvBuffer.getPointer().getString(0));     //输出结果:pvBuffer的值被改变,是正确的值
            }
    }
      

  2.   

    还要import下才行
    import com.sun.jna.ptr.ByteByReference;