

![]() | 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: |
14 messages in net.java.dev.jna.usersRe: [jna-users] Problem Regarding Str...| From | Sent On | Attachments |
|---|---|---|
| Muhammad Noor | Apr 6, 2009 12:16 am | .dll, .log |
| Timothy Wall | Apr 6, 2009 3:49 am | |
| Muhammad Noor | Apr 6, 2009 4:11 am | |
| Timothy Wall | Apr 6, 2009 5:32 am | |
| Muhammad Noor | Apr 6, 2009 5:45 am | |
| Timothy Wall | Apr 6, 2009 6:13 am | |
| Muhammad Noor | Apr 6, 2009 6:22 am | |
| Timothy Wall | Apr 6, 2009 7:01 am | |
| Hristo Novatchkov | May 3, 2009 11:55 am | |
| Timothy Wall | May 3, 2009 12:56 pm | |
| Hristo Novatchkov | May 3, 2009 1:17 pm | |
| Timothy Wall | May 3, 2009 5:57 pm | |
| Novatchkov Hristo | May 4, 2009 4:05 am | |
| Timothy Wall | May 4, 2009 4:21 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] Problem Regarding Structure that includes Function Pointers | Actions... |
|---|---|---|
| From: | Muhammad Noor (muha...@raseen.ae) | |
| Date: | Apr 6, 2009 4:11:11 am | |
| List: | net.java.dev.jna.users | |
Hi Mr. *Timothy Wall*
I have tried to my example by using StdCallLibrary and StdCallLibrary but I am still facing same problem. Please note my last exposed method which has been executed successfully. I just want to know that why it does not works when I pass structure as argument.
Regards Noor.
On 4/6/09, Timothy Wall <twal...@dev.java.net> wrote:
Your C code uses the stdcall calling convention. Your JNA library mapping and its callbacks need to do the same (https://jna.dev.java.net/#w32crash ).
You're also unnecessarily assigning your structure a size of two bytes, which is not enough for two function pointers.
On Apr 6, 2009, at 3:17 AM, Muhammad Noor wrote:
To whom it may concern.
Hi,
I am using JNA for accessing DLL functions directly from JAVA, but I am stuck in a situation when I have to access a method that takes structure as a parameter which includes Function Pointers in it.
My problem is that JNA does not call my callback functions when their function pointers are part of a structure which is then passed as an argument to a C++ function.
In order to get a clearer picture of my problem please have a look at the code.
===================C++ Header File=================== typedef int (__stdcall *StringRevFunction) (); typedef int (__stdcall *StringAscFunction) (int val);
typedef struct TUssdCallbacks { StringAscFunction stringAscFunction; StringRevFunction stringRevFunction; };
extern "C" __declspec(dllexport) void RegisterStringCallbackFunc(TUssdCallbacks tUssdCallbacks);
===================C++ Implementation File=================== #include "stdafx.h" #include "CCallbackFunction.h"
extern "C" __declspec(dllexport) void RegisterStringCallbackFunc(TUssdCallbacks tUssdCallbacks){
(*tUssdCallbacks.stringAscFunction)((int)8);
(*tUssdCallbacks.stringRevFunction)(); }
===================Java Interface definition file===================
import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Structure;
public interface CCallbackFunction extends Library{
CCallbackFunction INSTANCE = (CCallbackFunction) Native.loadLibrary("CCallbackFunction",CCallbackFunction.class);
public static class TUssdCallbacks extends Structure{
public TUssdCallbacks (StringRevFunction stringRevFunction,StringAscFunction stringAscFunction){ super(2,ALIGN_DEFAULT); this.stringAscFunction = stringAscFunction; this.stringRevFunction = stringRevFunction; }
public StringRevFunction stringRevFunction; public StringAscFunction stringAscFunction; }
public void RegisterStringCallbackFunc(TUssdCallbacks tUssdCallbacks);
}
===================Java Main File===================
import com.sun.jna.Function;
public class Test {
public static void main(String[] args) { System.setProperty("jna.library.path","C:\\lib\\"); String s = System.getProperty("jna.library.path"); System.out.println( "Jna.library.path = "+s );
CCallbackFunction.StringAscFunction stringAscFunction = new CCallbackFunction.StringAscFunction(){
public int invoke() { System.out.println("------**-------"); return 0; }
};
CCallbackFunction.StringRevFunction stringRevFunction = new CCallbackFunction.StringRevFunction(){
public int invoke(int val) { System.out.println("-------**------"+val); return 0; }
};
CCallbackFunction.TUssdCallbacks callbacks = new CCallbackFunction.TUssdCallbacks(stringRevFunction,stringAscFunction);
CCallbackFunction.INSTANCE.RegisterStringCallbackFunc(callbacks);
}
}
The last highlighted line results in following error.
# # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02dc2610, pid=3380, tid=5456 # # Java VM: Java HotSpot(TM) Client VM (11.0-b15 mixed mode, sharing windows-x86) # Problematic frame: # C 0x02dc2610 # # An error report file with more information is saved as: # D:\workspace\JavaJNA\hs_err_pid3380.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. #
NOTE:
I have accessed same DLL in C# and it successfully calls my call back function. Moreover I have exposed another function in DLL with all the Function pointers as method parameter and then within the function I have initialized the structure with Function Pointer values and called same method which results in successful call to my callback functions that I have defined in JAVA.
The new exposed function is as follows.
extern "C" __declspec(dllexport) void RegisterStrCallbackFunc(StringRevFunction stringRevFunction,StringAscFunction stringAscFunction){ struct TUssdCallbacks tUssdCallbacks = { stringAscFunction,stringRevFunction};
RegisterStringCallbackFunc(tUssdCallbacks); }
Kindly guied me is it possible to register my callback functions using structure. If it is then please tell where am I doing wrong.
Thanking you in anticipation.
Regards,
Muhammad Noor-ul-haque
You can call me just noor.
<CCallbackFunction.dll><hs_err_pid3380.log>--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net








.dll, .log