

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
2 messages in net.java.dev.jna.users[jna-users] Contiguous Elements in Ar...| From | Sent On | Attachments |
|---|---|---|
| RWAD...@UP.COM | Jun 19, 2008 9:09 am | |
| RWAD...@UP.COM | Jun 20, 2008 5:33 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] Contiguous Elements in Array of Structures | Actions... |
|---|---|---|
| From: | RWAD...@UP.COM (RWAD...@UP.COM) | |
| Date: | Jun 19, 2008 9:09:03 am | |
| List: | net.java.dev.jna.users | |
I'm getting this exception even though I use the Structure.toArray() method to create the structure arrays. We're passing only two multi-element arrays into the failing method, and both are set up with the toArray() method. Unfortunately, I couldn't find a working of example of using the toArray method and then passing the array of structures as a method argument. Any insight on this would be GREATLY appreciated!
__________________________________
Exception in thread "main" java.lang.IllegalArgumentException: Structure array elements must use contiguous memory (at element index 1) at com.sun.jna.Function.convertArgument(Function.java:449) at com.sun.jna.Function.invoke(Function.java:203) at com.sun.jna.Library$Handler.invoke(Library.java:204) at $Proxy0.efm207_collect_tracks_of_paths(Unknown Source) at com.uprr.efm.subroutines.Efm207.getTracksInPaths(Efm207.java:34 ) at com.uprr.efm.subroutines.Efm207.main(Efm207.java:45)
________________________________________________
Here's the basic code, with the failing method call in red:
________________________________________________
package com.uprr.efm.subroutines;
import com.sun.jna.Structure; import com.uprr.efm.Efms; import com.uprr.efm.structures.EntityRangeStructure; import com.uprr.efm.structures.PathRangeStructure; import com.uprr.efm.structures.TrackTypeIdentifierStructure;
//---------------------------------------------------------------------------------------------- public class Efm207 {
EntityRangeStructure[] ranges = (EntityRangeStructure[])(new EntityRangeStructure().toArray(3));
public void getTracksInPaths(PathRangeStructure[] paths) {
int[] inOutCount = new int[1]; int facilityEntityNumber = 12112; double startMile = 276.140; double endMile = 313.970;
Efms.API.INSTANCE.efm207_collect_tracks_of_paths(facilityEntityNumber, startMile, endMile, (short)paths.length, paths, inOutCount, ranges, ranges.length); Efms.checkForErrors(); } //---------------------------------------------------------------------------------------------- public static void main(String[] args) {
Efm207 module = new Efm207();
PathRangeStructure[] ranges = getTestRanges(); module.getTracksInPaths(ranges); System.out.println(module.getRanges()); } //---------------------------------------------------------------------------------------------- private static PathRangeStructure[] getTestRanges() { TrackTypeIdentifierStructure tti = new TrackTypeIdentifierStructure();
tti.segm_sys_nbr = 2165 ; tti.trk_type_code = "SIMN"; tti.zts_sys_nbr = 0 ;
PathRangeStructure[] paths = (PathRangeStructure[])new PathRangeStructure().toArray(2);
paths[0] = new PathRangeStructure(); paths[1] = new PathRangeStructure();
paths[0].tti = tti; paths[0].path_nbr = 98214; paths[0].trk_nbr = 12112; paths[0].path_lgth = 686.4; paths[0].lo_rpl_nbr = 1502698; paths[0].lo_anlz_rl_nbr = 1104478; paths[0].lo_mile_valu = 276.14; paths[0].hi_rpl_nbr =2038739; paths[0].hi_anlz_rl_nbr = 1104538; paths[0].hi_mile_valu = 276.27;
paths[1].tti = tti; paths[1].path_nbr = 98215; paths[1].trk_nbr = 12112; paths[1].path_lgth = 13041.6; paths[1].lo_rpl_nbr = 2038740; paths[1].lo_anlz_rl_nbr = 1104538; paths[1].lo_mile_valu = 276.27; paths[1].hi_rpl_nbr =2023035; paths[1].hi_anlz_rl_nbr = 1096022; paths[1].hi_mile_valu = 278.74;
return paths; } }
________________________________________________
This module provides the prototype for the failing function:
________________________________________________
package com.uprr.efm;
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.ptr.ByteByReference; import com.uprr.efm.structures.EntityRangeStructure; import com.uprr.efm.structures.NetPathLocationStructure; import com.uprr.efm.structures.PathRangeStructure;
//----------------------------------------------------------------------------------------------
public class Efms {
public interface API extends Library {
API INSTANCE = (API)Native.loadLibrary("c:/upapps/efm/bin/efms-api.dll", API.class); void efm207_collect_tracks_of_paths(int in_fac_enty_nbr, double in_bgng_mile, double in_endg_mile,short path_cnt, PathRangeStructure paths[], int[] out_cnt, EntityRangeStructure output[], int max_output); } }
_____________________________________________
And finally, here's the native code we're trying to call
_____________________________________________
void efm207_collect_tracks_of_paths(SYSNBR in_fac_enty_nbr, double in_bgng_mile, double in_endg_mile, short int path_cnt, Path_Range_Struct paths[], long int *out_cnt, Enty_Range_Struct output[], long int max_output) { extern Global global; char previous_path[PATH_LEN]; extern char msg_str[ERR_MSG_LEN];
short int p; BOOL full_path = FALSE; long int i, j;
strcpy(previous_path, global.current_path); sprintf(global.current_path, PATH_FORMAT, PROGRAM_ID, previous_path); ...
.
This message and any attachments contain information from Union Pacific which
may be confidential and/or privileged.
If you are not the intended recipient, be aware that any disclosure, copying,
distribution or use of the contents of this message is strictly prohibited by
law. If you receive this message in error, please contact the sender immediately
and delete the message and any attachments.







