

![]() | 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: |
10 messages in net.java.dev.jna.usersRe: [jna-users] Callback doesn't work...| From | Sent On | Attachments |
|---|---|---|
| bao bao | Jun 14, 2009 8:16 pm | |
| Timothy Wall | Jun 15, 2009 3:55 am | |
| bao bao | Jun 15, 2009 4:43 am | |
| Timothy Wall | Jun 15, 2009 5:16 am | |
| bao bao | Jun 15, 2009 6:35 pm | |
| Timothy Wall | Jun 16, 2009 3:27 am | |
| bao bao | Jun 16, 2009 7:15 am | |
| bao bao | Jun 16, 2009 8:14 pm | |
| Timothy Wall | Jun 17, 2009 3:43 am | |
| bao bao | Jun 21, 2009 5:46 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] Callback doesn't work at all. | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Jun 15, 2009 3:55:08 am | |
| List: | net.java.dev.jna.users | |
On Jun 14, 2009, at 11:17 PM, bao bao wrote:
Here is my code: // SimpleDll.cpp : Defines the entry point for the DLL application. //
#include "stdafx.h" #include "stdio.h" #include <iostream> #include <cstdlib>
using namespace std;
#ifdef DLLDIR_EX #define DLLDIR __declspec(dllexport) // export DLL information
#else #define DLLDIR __declspec(dllimport) // import DLL information
#endif
// Original C declarations typedef void (*FUNCTION)(); extern "C" __declspec(dllexport) int helloexit(FUNCTION);
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }
void FinalFunction(void) { cout<<"Final function called";
}
extern "C" __declspec(dllexport) int helloexit(FUNCTION c) { atexit(FinalFunction); return 123; }
import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native;
public interface ISimpleDll extends Library { ISimpleDll INSTANCE = (ISimpleDll) Native.loadLibrary("SimpleDll", ISimpleDll.class);
public static interface FUNCTION extends Callback { public void callback(); }
int helloexit(FUNCTION function);
}
public class SimpleDll {
ISimpleDll lib = ISimpleDll.INSTANCE;
/** * */ public SimpleDll() { new Thread() { public void run() { int t = lib.helloexit(new FUNCTION() { public void callback() { System.out.println("exit was called"); } }); System.out.println(t); } }.start(); }
/** * @param args */ public static void main(String[] args) { new SimpleDll(); }
}
The ouput is: 123 Final function called Now, the callback method never invoked, what's wrong with my code?
Why would you expect your callback to be called? When would you expect it to be called?







