调用vc写的DLL,接口SetPChar(int x, LPDEMO7_CHAR lpchar)
LPDEMO7_CHAR的结构为:
typedef struct _DEMO_7CHAR
{
char sName[50];
char sc;
}DEMO_7CHAR, *LDEMO_7CHAR;
在java里这样调用:
         public static class Demo7 extends Structure{
public byte Sname[] =new byte[50];
public byte sc;
}
public static void  main (String args[]){
          Demo7 sss=new Demo7();
          String str="a";
          sss.sc='a';
                    byte[] bt=(str+'\0').getBytes("GBK");
    sss.Sname=bt ;
    int c=demo.INSTANCE.SetPChar(5, sss);
}
结果是只显示一个变量的值sc或者sName
也就是说dll中只能正常显示sc的值 或者sname的值,
想把这两个值都显示出来

解决方案 »

  1.   

    简单来说就是单传byte数组 可以 但是传1个以上 只能接受一个数组,
      

  2.   

    官网如下说:Referencing Java Objects
    Primitive types, such as integers, characters, and so on, are copied between Java and native code. Arbitrary Java objects, on the other hand, are passed by reference. The VM must keep track of all objects that have been passed to the native code, so that these objects are not freed by the garbage collector. The native code, in turn, must have a way to inform the VM that it no longer needs the objects. In addition, the garbage collector must be able to move an object referred to by the native code.
    大致意思是不得将类作为参数传递.这个问题搞了一整天,头都疼了.有本书,先看看吧.
    http://download.csdn.net/download/changdongdong1987/3887265