1 message in net.java.dev.jna.usersProblems on mapping C Struct and JNA ...
FromSent OnAttachments
FlávioApr 30, 2008 8:25 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Problems on mapping C Struct and JNA Structure classActions...
From:Flávio (flav@yahoo.com.br)
Date:Apr 30, 2008 8:25:23 am
List:net.java.dev.jna.users

Hi all.

I'm getting problems on mapping Struct and Srtucture class. Source code below:

1- Class extending Structure:

import com.sun.jna.Structure;

public class Str1 extends Structure { public int a; public int b; }

2 - Interface Struct DLL:

import com.sun.jna.win32.StdCallLibrary;

public interface StructDLL extends StdCallLibrary{ public Str1 FuncaoTeste(); }

3 - Class responsible for loading DLL and calling the function:

import com.sun.jna.Native;

public class StructAccessDLL { private static StructDLL structDLL = null;

public StructAccessDLL(){ estruturaDLL = (EstruturaDLL) Native.loadLibrary ("testStruct", StructDLL.class); }

public Str1 callTestFunction(){ return structDLL.TestFunction(); } }

4 - Class testing DLL access:

public class StructDLLTest { private static StructAccessDLL structAccessDLL = new StructAccessDLL();

public static void main(String[] args) { Str1 str1 = structAccessDLL.callTestFunction();

System.out.println(str1.a); System.out.println(str1.b); } }

5 - C Struct:

struct Str1{ int a,b; };

6 - DLL function:

Str1 TestFunction() { struct Str1 info; info.a=1; Beep(500,1000); info.b=2; Beep(1000,1000); return info; }

7 - Exception log file:

# # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x75f49922, pid=4528, tid=5708 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_12-b04 mixed mode, sharing) # Problematic frame: # C [MSVCRT.dll+0x9922] # # An error report file with more information is saved as hs_err_pid4528.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp #

I don't know why the mapping Struct x Structure fails. I thank any help too much.

Regards.

Flávi