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?