ochafik/nativelibs4java — Issue #281: BridJ: Return Integer by Value
Author: aeduroth
Created: 2012-03-07 14:30:09+00:00
State: open

Hi there BridJ community!

(bug report as requested here: http://groups.google.com/group/nativelibs4java/browse_thread/thread/9556c41add36a446)

I have an Interface IModule.h:
class IModule {
public:
virtual ~IModule() {};
virtual int add(int a, int b) = 0;
virtual int subtract(int a, int b) = 0;
};

And an Implementation AModule.h:
#include "IModule.h"

class AModule : public IModule {
public:
AModule();
virtual ~AModule();

virtual int add(int a, int b);
virtual int subtract(int a, int b);
};

And the actual implementation AModule.cpp:
#include "AModule.h"
AModule::AModule() {}
AModule::~AModule() {}
int AModule::add(int a, int b) {
return a + b;
}

int AModule::subtract(int a, int b) {
return a - b;
}

Then I generated the BridJ Wrappers using the following command (Where
Jnaerator does a awesome job in detecting the interface and preserving
the hierarchy (interface -> implementation) in Java!!!):
java -jar jnaerator-0.9.10-SNAPSHOT-20120306.jar -runtime BridJ -
library MyCppModules *Module.h -noComp -noJar
Then I wrote the following Java application which prints the result
2109657008 where I expect 9 ;-) What I'm doing wrong??
import mycppmodules.AModule;
import mycppmodules.IModule;
public class BridJTest {
public static void main(String[] args) {
new BridJTest();
}
public BridJTest() {
IModule module = new AModule();
System.out.println(module.add(4, 5));
}
}

Thanks in Advance
Adrian

Using Mac 10.7 but also tried it with Ubuntu