C:
					
typedef struct Example6Struct {
	int val;
} Example6Struct;
...
int example6_sendStructArray(const Example6Struct* vals, int numVals)
{
	int loop = 0;
	int total = 0;
	for (loop=0; loop<numVals; loop++)
	{
		total += vals[loop].val;
	}
	return total;
}
					
				
Java:
					
public interface CLibrary extends Library {
	public static class Example6Struct extends Structure {
		public static class ByReference extends Example6Struct implements Structure.ByReference {}
		
		public int val;
	}
	...
	public int example6_sendStructArray(Example6Struct.ByReference vals, int numVals);
}
...
CLibrary clib = (CLibrary)Native.loadLibrary("testlib", CLibrary.class);
...
CLibrary.Example6Struct.ByReference e6ref = new CLibrary.Example6Struct.ByReference();
// Structure.toArray 分配一块连续的内存
// 如果数据比较大,可能会很慢,这里主要做测试
CLibrary.Example6Struct[] vals = (CLibrary.Example6Struct[])e6ref.toArray(3);
vals[0].val = 1;
vals[1].val = 2;
vals[2].val = 3;
int total = clib.example6_sendStructArray(e6ref, 3);
System.out.println("example 6: " + total);
//www.sitcoder.com
				        
                        
                                                                    
						
						
						
									  				


	
色迷迷 哭 呕吐 大笑 口水 微笑 啵一个 发怒

Hi,您需要填写昵称和邮箱!

  • 必填项
  • 必填项