

![]() | 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: |
22 messages in net.java.dev.jna.usersRe: [jna-users] Structure by value an...| From | Sent On | Attachments |
|---|---|---|
| Edroaldo Lummertz da Rocha | Nov 7, 2008 3:21 pm | |
| Timothy Wall | Nov 7, 2008 4:44 pm | |
| Edroaldo Lummertz da Rocha | Nov 10, 2008 6:07 am | |
| Timothy Wall | Nov 10, 2008 6:34 am | |
| Edroaldo Lummertz da Rocha | Nov 10, 2008 6:59 am | |
| Timothy Wall | Nov 10, 2008 7:57 am | |
| Edroaldo Lummertz da Rocha | Nov 10, 2008 8:38 am | |
| Timothy Wall | Nov 10, 2008 10:40 am | |
| Edroaldo Lummertz da Rocha | Nov 10, 2008 12:17 pm | |
| Timothy Wall | Nov 10, 2008 1:46 pm | |
| Edroaldo Lummertz da Rocha | Nov 10, 2008 1:57 pm | |
| Timothy Wall | Nov 10, 2008 6:27 pm | |
| Edroaldo Lummertz da Rocha | Nov 11, 2008 3:25 am | |
| Edroaldo Lummertz da Rocha | Nov 11, 2008 3:40 am | |
| Edroaldo Lummertz da Rocha | Nov 12, 2008 6:42 am | |
| Edroaldo Lummertz da Rocha | Nov 14, 2008 3:46 am | |
| Timothy Wall | Nov 14, 2008 4:37 am | |
| Edroaldo Lummertz da Rocha | Nov 14, 2008 9:41 am | |
| Edroaldo Lummertz da Rocha | Nov 14, 2008 10:05 am | |
| Timothy Wall | Nov 14, 2008 11:31 am | |
| Edroaldo Lummertz da Rocha | Nov 17, 2008 4:35 am | |
| Timothy Wall | Nov 17, 2008 5:17 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: | Re: [jna-users] Structure by value and reference | Actions... |
|---|---|---|
| From: | Edroaldo Lummertz da Rocha (edro...@gmail.com) | |
| Date: | Nov 10, 2008 6:07:08 am | |
| List: | net.java.dev.jna.users | |
Hello, I do not why, but my struct in not being correctly initialized. Everything looks like fine, but is not working. How can I write my Structure class? My new in JNA, so sorry for these questions. My HSymTbl in JNA is:
public static class HSymTbl extends Structure { public static class ByValue extends HSymTbl implements Structure.ByValue{ } public long pSymTbl; public long length; }
I think that I have problems with pointers. I am going to post parts of my code here to help (in JNA and Visual C++). The source in Visual C++ is provided by fabricant of DLL.
*System.setProperty("jna.library.path", "C:\\sranger");* SignalRangerInterface sranger = (SignalRangerInterface)Native.loadLibrary("SRanger_HL", SignalRangerInterface.class); String boardId = "Ranger0"; PointerByReference hDev = new PointerByReference(); //HSymTbl sym = new HSymTbl(); HSymTbl.ByValue by = new HSymTbl.ByValue(); short AICp[] = new short[33];
AICp[0]=8;AICp[1]=25168;AICp[2]=16976;AICp[3]=8784;AICp[4]=592;AICp[5]=25168;
AICp[6]=16976;AICp[7]=8784;AICp[8]=592;AICp[9]=25601;AICp[10]=17409; AICp[11]=9217; AICp[12]=1025;AICp[13]=25601;AICp[14]=17409;AICp[15]=9217; AICp[16]=1025;AICp[17]=26113; AICp[18]=17921;AICp[19]=9729;AICp[20]=1537;AICp[21]=26113;AICp[22]=17921;AICp[23]=9729; AICp[24]=1537;AICp[25]=26639;AICp[26]=18447;AICp[27]=10255;AICp[28]=2063;AICp[29]=26639; AICp[30]=18447;AICp[31]=10255;AICp[32]=2063;
*int value = sranger.Initialize_HL(boardId, hDev);* short nbWords = 33; long dspAddress = -1; int ret = 0;
*value = sranger.LoadUser_HL(hDev, path, by);*
if (value == 0) { *ret = sranger.K_Move_Data_HL(hDev, 0, nbWords, AICp, dspAddress, 1, "_aicreg", by);* JOptionPane.showMessageDialog(null, "Codigo carregado com sucesso: " + value); if (ret == 0) { JOptionPane.showMessageDialog(null, "KMove Ok: " + ret); } else { JOptionPane.showMessageDialog(null, "KMove ferrou: " + ret); } }else{ JOptionPane.showMessageDialog(null, "Erro ao carregar codigo: " + value); }
Well, this is the Java code. Now, I write the Visual C++ code and I would like to know if my Java code is correct.
---------------------------------------------------------------------------------------------------------------------------------- Where refnum is void **refnum;
PCHAR Board_id="Ranger0"; int ret;
// Call Initialize_HL (refnum is define at the beginning of this file)
* ret=Initialize_HL(Board_id,&refnum);*
unsigned short AICp[34];
AICp[0]=8;AICp[1]=25168;AICp[2]=16976;AICp[3]=8784;AICp[4]=592;AICp[5]=25168;
AICp[6]=16976;AICp[7]=8784;AICp[8]=592;AICp[9]=25601;AICp[10]=17409;AICp[11]=9217;
AICp[12]=1025;AICp[13]=25601;AICp[14]=17409;AICp[15]=9217;AICp[16]=1025;AICp[17]=26113;
AICp[18]=17921;AICp[19]=9729;AICp[20]=1537;AICp[21]=26113;AICp[22]=17921;AICp[23]=9729;
AICp[24]=1537;AICp[25]=26639;AICp[26]=18447;AICp[27]=10255;AICp[28]=2063;AICp[29]=26639; AICp[30]=18447;AICp[31]=10255;AICp[32]=2063;
// Load Demo2_sr.out
char path[]="Demo2_sr.out"; unsigned short buffer[10]; int ret,rettem;
// refnum and Sym are define at the beginning of this file
* ret=LoadUser_HL(&refnum,path,&Sym);*
rettem=-1;
if (ret==0) { // Load AIC parameters (_aicreg)
* rettem=K_Move_Data_HL(&refnum,FALSE,33,&AICp[0],-1,1,"_aicreg",Sym);*
Where the bold text is the functions of DLL that I need. I am going to post the signatures of java functions and the C++ function, for comparasion. I cannot see the errors, the type mapping is correct? I do not get compiler errors and do not get execution error, just does not work.
Java Assignatures:
public interface SignalRangerInterface extends Library { public int Initialize_HL(String boardId, PointerByReference hDev); public int LoadUser_HL(PointerByReference hDev, String filePath, SignalRanger.HSymTbl pSymTable); public int K_Move_Data_HL(PointerByReference hDev, int rw, short nbWords, short[] buffer, long dSPAdrress, int memSpace, String symbol, SignalRanger.HSymTbl.ByValue symTable); public int ExecUser_HL(PointerByReference hDev, long dSPAddress, String symbol, SignalRanger.HSymTbl.ByValue pSymTable); public int Load_Kernel_HL(PointerByReference hDev); public int DriverClose_HL(PointerByReference hDev); public int Find_Label_HL(String label, SignalRanger.HSymTbl.ByValue symTable); }
C++ signatures
int Initialize_HL(PCHAR BoardID,void ** hDev); int K_Move_Data_HL(void ** hDev,BOOL RW,unsigned short Nb_Words, unsigned short * Buffer,signed long DSPAddress, int MemSpace,char * Symbol,struct HSymTbl SymTable);
LoadUser_HL(void ** hDev,char * FilePath,struct HSymTbl * pSymTable);
Sorry for a so long e-mail, but I need to solve this problem. Thank so much for help and understanding.
2008/11/7 Timothy Wall <twal...@dev.java.net>
On Nov 7, 2008, at 6:22 PM, Edroaldo Lummertz da Rocha wrote:
Hello, I have the following problem: I have a struct like this:
struct HSymTbl { unsigned long pSymTbl; unsigned long length; }; and I need to call the following function:
int LoadUser_HL(void ** hDev,char * FilePath,struct HSymTbl * pSymTable);
This way, I just to use a Structure subclass and pass my Structure object by reference, is it correct? I do it and works fine, but after I need to call the following function:
K_Move_Data_HL(void ** hDev,BOOL RW,unsigned short Nb_Words, unsigned short * Buffer,signed long DSPAddress, int MemSpace,char * Symbol,struct HSymTbl SymTable);
and here, I need do pass a Structure by value. How can I do it? I have already tried to implement the interfaces Signature.ByReference and Signature.ByValue, but I can not understand how to use the Signature SymTable as a reference in a moment and as value in another moment. May You might help me please?
In this case you can use MyStructure.ByValue in both cases, as long as the function interface declares the appropriate usage. MyStructure.ByValue will work in the first function because it derives from MyStructure, and the function signature takes precedence over the actual type passed in (so the ByValue attribute is ignored in the first case).
-- Edroaldo Lummertz da Rocha, Computer Scientist Mestrando em Engenharia Elétrica Master student in Electrical Engineering GruDE - LCI - EEL - CTC - UFSC Phn. +55(48)37217720 http://www.eel.ufsc.br/~lci/grude Mude Sua Vida, Mude o Mundo







